2012-09-06 79 views
-1

在這裏,我必須解析從前一個活動成功的值到下一個活動...現在我希望需要該值是保存在我的edittext字段...我怎麼能開發這個。 。解析值保存在edittext字段android

在我的代碼已經到訂單ID值從之前的活動解析,並在此顯示activity.here將訂單值保存在我的EditText自動場......我該怎麼辦......

在我以前的活動代碼:

Button btninsert = (Button) findViewById(R.id.btn_insert); 
btninsert.setOnClickListener(new View.OnClickListener() { 


public void onClick(View v) { 
    String s= getIntent().getStringExtra("orderid"); 
Intent i = new Intent(getApplicationContext(), InsertionExample.class); 
i.putExtra(KEY_NAME, s); 
startActivity(i); 
} 
}); 

這是我的InsertionExample.java類:

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"; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.change_status); 
    Intent in = getIntent(); 

    // Get XML values from previous intent 
    String orderid = in.getStringExtra(KEY_NAME); 

    // Displaying all values on the screen 
    TextView lblName = (TextView) findViewById(R.id.textView1); 


    lblName.setText(orderid); 


    Spinner spinner = (Spinner) findViewById(R.id.spinner1); 
    btninsert = (Button)findViewById(R.id.btn_insert1); 
    btninsert.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      EditText Orderid = (EditText) findViewById(R.id.orderid); 
      String orderid = Orderid.getText().toString(); 
     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. 
    } 
} 

在這裏,我已經使用以下代碼設置的EditText字段的訂單ID:idProp.setValue(訂單ID);/

  EditText Orderid = (EditText) findViewById(R.id.orderid); 
      String orderid = Orderid.getText().toString(); 
      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);` 

,但我希望需要的EditText字段必須自動進入我解析的orderid。 (IE)

Intent in = getIntent(); 

    // Get XML values from previous intent 
    String orderid = in.getStringExtra(KEY_NAME); 

    // Displaying all values on the screen 
    TextView lblName = (TextView) findViewById(R.id.textView1); 


    lblName.setText(orderid); 

這是訂單ID自動進入的EditText中...我該怎麼辦.. 請幫助我,給我一些想法。

+0

您正在使用eclipse,對不對?請在發佈之前按ctrl + shift + f並格式化您該死的代碼。另外,如果它不能編譯,它會很好,因爲你似乎已經發布了它,就像你希望人們嘗試或閱讀它一樣。 – Shark

回答

0

其希望值發送給其他會做這樣的活動.....

Button bn = (Button)findViewById(R.id.bn); 
bn.setOnClickListener(new OnClickListener() { 

    public void onClick(View arg0) { 
     Intent intent = new Intent(PutExtra.this, getExtra.class); 
     intent.putExtra("text", et.getText().toString()); 
     startActivity(intent); 
    } 
}); 

它被調用,並希望活動S中的值將不得不這樣做

override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.getextra); 

     EditText tv = (EditText)findViewById(R.id.tv); 

     Intent intent = getIntent(); 
     String extra = intent.getStringExtra("text");  
     tv.setText(extra); 
    } 
+0

請閱讀我更新的問題,併爲我提供此解決方案。 –

+0

好的。您確實想要使用您的編輯文本? 你想把你從getStringExtra()鑽進編輯文本 OR 你沒有把這個值在編輯文本 –

+0

我得到這個 –