2012-09-11 18 views
1

我開發了一個應用程序。我必須解析從一個活動到下一個活動的值。解析值顯示在textview意味着成功顯示。但是解析值顯示在微調器上意味着該值不顯示在這個應用程序中。從上一個活動解析值,並顯示在當前活動在android中的微調框字段

這是我的代碼:

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; 

static final String KEY_NAME = "orderid"; 
static final String KEY_STATUS = "status"; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.change_status); 
    TextView tv = (TextView) findViewById(R.id.textView1); 
    tv.setText(getIntent().getExtras().getString("status")); 


    Spinner spinner = (Spinner) findViewById(R.id.spinner1); 
    btninsert = (Button)findViewById(R.id.btn_insert1); 
    btninsert.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent in = getIntent(); 
      String orderid = in.getStringExtra(KEY_NAME); 
      String status = in.getStringExtra(KEY_STATUS); 

      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); 
      PropertyInfo idProp =new PropertyInfo(); 
      idProp.setName("Orderid");//Define the variable name in the web service method 
      idProp.setValue(orderid);//Define value for fname variable 
      idProp.setType(String.class);//Define the type of the variable 
      request.addProperty(idProp); 



       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> adapter = new ArrayAdapter<String>(this, 
      android.R.layout.simple_spinner_item, list); 
    //set the view for the Drop down list 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    //set the ArrayAdapter to the spinner 
    spinner.setAdapter(adapter); 
    adapter.notifyDataSetChanged(); 
    //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. 
    } 
} 

這裏的狀態從透水活動和顯示使用的TextView意味着它的運作良好,解析當前的活動......但我想需要分析得到的值是微調顯示器。如何管理上面的代碼。請幫助我。

回答

0

嗨,我用下面的code.it是我的工作。

Intent in = getIntent(); 
    String status = in.getStringExtra(KEY_STATUS); 

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

是的,我必須在列表中添加狀態。

0

試試這個:

Spinner.setOnTouchListener(new OnTouchListener() { 
     public boolean onTouch(View v, MotionEvent event) { 
Spinner.setAdapter(new ArrayAdapter<String>(InsertionExample.this, android.R.layout.simple_spinner_item,list);; 
}}); 
1

你必須保持下拉列表。 如果解析的值是新項目,則必須添加到列表並通知適配器。 如果解析值爲現有值,則可以在列表中找到項目位置並設置微調器選定的項目位置。

// to set the spinner selected item 
spinner.setSelection(position); 
相關問題