简体   繁体   English

在android中单击按钮时更新微调器值

[英]update spinner value while click button in android

in my app have 2 fields..they are 1 spinner and 1 button...here i have to select the spinner value and click the submit button means the spinner value is updated dynamically..how is to do...i have to developed update the spinner value use statically..i wish to need to update the spinner value is dynamically...how can i do..please give me some ideas. 在我的应用程序中有2个字段..它们是1个微调器和1个按钮...在这里,我必须选择微调器值,然后单击“提交”按钮,意味着该微调器值是动态更新的..怎么办...我必须开发的更新Spinner值静态使用..我希望需要动态更新Spinner值...我该怎么办..请给我一些想法。

i have use below code: 我使用下面的代码:

public class InsertionExample extends Activity {
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://192.168.1.168:8089/XcartLogin/services/update?wsdl";
private final String SOAP_ACTION = "http://xcart.com/insertData";
private final String METHOD_NAME = "insertData";
Button btninsert;
String selectedItem;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.change_status);

  //  TextView tv = (TextView) findViewById(R.id.textView1);    
  // tv.setText("Welcome ,"+getIntent().getExtras().getString("orderid"));
    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    btninsert = (Button)findViewById(R.id.btn_insert1);
    btninsert.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            PropertyInfo unameProp =new PropertyInfo();
            unameProp.setName("Status");//Define the variable name in the web service method
            unameProp.setValue(selectedItem);//Define value for fname variable
            unameProp.setType(String.class);//Define the type of the variable
            request.addProperty(unameProp);


              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
              envelope.setOutputSoapObject(request);
              HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

              try{
               androidHttpTransport.call(SOAP_ACTION, envelope);
                  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

                 TextView result = (TextView) findViewById(R.id.textView2);
                  result.setText(response.toString());
             }
           catch(Exception e){

           }
              }
    });

    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
    //Dynamically generate a spinner data 
    createSpinnerDropDown();

}

//Add animals into spinner dynamically
private void createSpinnerDropDown() {

    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

    //Array list of animals to display in the spinner
    List<String> list = new ArrayList<String>();

    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");

    //create an ArrayAdaptar from the String Array
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    //set the view for the Drop down list
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //set the ArrayAdapter to the spinner
    spinner.setAdapter(dataAdapter);
    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

}

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

         selectedItem = parent.getItemAtPosition(pos).toString();

 }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }



    }

    public void onNothingSelected(AdapterView<?> parent) {
        // Do nothing.
    }
}

You can use notifyDataSetChanged() on your adapter. 您可以在适配器上使用notifyDataSetChanged() It will be able to change data dynamically in the Spinner. 它将能够在微调器中动态更改数据。

adapter.notifyDataSetChanged();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM