2011-11-08 66 views
0

下面給出了頁面加載期間,我有一個Spinner Control與來自Sqllite的數據綁定。需要在Spinner控件中選擇Sqlite保存的數據

public void BindSpinner() { 
     ArrayList<HashMap<String, String>> alist = new ArrayList<HashMap<String, String>>(); 
     HashMap<String, String> map = new HashMap<String, String>(); 
     Cursor cursor; 
     delivary_helper deliveryHelper; 
     SimpleAdapter simpleAdapter; 
     deliveryHelper = new delivary_helper(this); 
     cursor = deliveryHelper.GetProblemCodes(); 
     cursor.moveToFirst(); 

     for (int i = 0; i < cursor.getCount(); i++) { 
      map = new HashMap<String, String>(); 

      map.put("Deliv_Issue2_PKProblemCode", 
        cursor.getString(cursor.getColumnIndex("PKProblemCode"))); 
      map.put("Deliv_Issue2_ProblemCode", 
        cursor.getString(cursor.getColumnIndex("ProblemCode"))); 
      map.put("Deliv_Issue2_ProblemCodeDescription", cursor 
        .getString(cursor.getColumnIndex("ProblemCodeDescription"))); 
      map.put("Deliv_Issue2_VWReturn", 
        cursor.getString(cursor.getColumnIndex("VWReturn"))); 
      alist.add(map); 
      cursor.moveToNext(); 
     } 

     simpleAdapter = new SimpleAdapter(this, alist, 
       R.layout.delivery_issue_2_spinner_row, new String[] { 
         "Deliv_Issue2_PKProblemCode", 
         "Deliv_Issue2_ProblemCode", 
         "Deliv_Issue2_ProblemCodeDescription", 
         "Deliv_Issue2_VWReturn" }, new int[] { 
         R.id.tvDelivIssue2PKProblemCode, 
         R.id.tvDelivIssue2ProblemCode, 
         R.id.tvDelivIssue2ProblemCodeDescription, 
         R.id.tvDelivIssue2VWReturn }); 
     delivery_line_problem.setAdapter(simpleAdapter); 
    } 

我保存了Sqllite數據庫表中Selected項的ID。

的問題是,當我保存微調控制數據和去throught其他頁面後返回到同一頁,我不能夠在微調control.How得到選擇保存的數據我可以選擇的項目我已經保存了,並且還需要將微調器與後面的數據完全綁定。

任何人都可以爲我提供解決方案。

回答

0

如果我正確地理解了你,你應該可以在你的微調器上設置一個OnItemSelectedListener。每當選擇一個項目時,將其保存到活動中的實例變量中。這樣你就會知道最後選擇的項目。所以像這樣:

yourSpinner.setOnItemSelectedSpinner(new AdapterView.OnItemSelectedListener(){ 
    public void onItemSelected (AdapterView<?> parent, View view, int position, long id){ 
    lastItemSelected = id; 
    } 
    public void onNothingSelected (AdapterView<?> parent){ 
    //do nothing here 
    } 
}); 
相關問題