2014-01-29 69 views
0

我在我的android應用程序中有2個活動,活動A有一個對象列表視圖,當我單擊時在活動B中顯示該對象的細節。活動B是同一活動,其中對象首先添加一個基本的輸入表單佈局。Android微調器設置項目活動啓動

我收到有關使用.getSerializableExtra() 從一個Intent在活動A.

我能爲我的編輯文本正確地檢索數據從活動的AN對象的信息,如名稱變量,它是輸入使用編輯文本:

et_medicationName.setText(med.getMedicationName()); 

但不能解決如何做我的微調相同?

因此,我在活動B上設置了微調項目以及其他字段,並在活動A(僅作爲標題)上保存了我的列表視圖中顯示的對象,但是如何在點擊時檢索選定的微調項目在活動A列表項在活動B.再次查看

這裏是我的序列化代碼,可能是使用的:

Serializable currentMed = getIntent().getSerializableExtra("Med"); 
    if(currentMed != null) 
    { 
     Medication med = (Medication)currentMed; 
     et_medicationName.setText(med.getMedicationName()); 

     //Get Medication Type from selected Spinner item here? 
    } 

我也有一個getter/setter方法設置了微調。

感謝您的幫助!

+0

spinner.setSelection(adapter.getPosition(「Stringvalue」)); –

回答

0

請嘗試此代碼。希望它對你有幫助。由於

Spinner spinnername1 = (Spinner) findViewById(R.id.spinner1); 
String mStr = spinnername1.getSelectedItem().toString(); 

對於通過值到意向

Intent mIntent = new Intent(CurrentActivity.this, NextActivity.class); 
mIntent.putExtra("Value", mStr); 
startActivity(mIntent); 

對於從意向中獲得價值。

Bundle bdl = getIntent().getExtras(); 
String mValue = bdl.getString("Value");