2011-11-21 56 views
0

我遇到了一個問題,實現紡紗廠並讓他們以我想要的方式工作。我有一個微調器包含從數組中填充的狀態縮寫。根據用戶選擇的狀態,應用程序應該執行數據庫查詢並填充第二個微調控件,其中商店的位置處於選定狀態。從數據庫填充的紡紗廠不註冊選擇

第一個微調工作正常,成功執行查詢並填充第二個微調。我想從第二個微調器獲得值並將其顯示在吐司消息中。這是問題發生的地方。第二個微調器在最初填充後未註冊點擊。

在下面的示例中,用戶從第一個微調框中選擇RI。第二個微調器被填充,並且微調器「COVENTRY」中的第一個城鎮顯示在烤麪包消息中。當我嘗試從第二個旋轉器中選擇其他城鎮時,問題就出現了......雖然城鎮被顯示在旋轉器中,但它們並沒有出現在吐司信息中。

if (parent.getItemAtPosition(pos).toString().equals("RI")) { 
      HDHelper hdtable = new HDHelper(getApplicationContext()); 
      hdtable.open(); 
      Cursor c = hdtable.fetchRI(); 
      if (c != null){ 
      SimpleCursorAdapter hdadapter1 = new SimpleCursorAdapter(getApplicationContext(), 
       android.R.layout.simple_spinner_item, c, // Give the cursor to the list adapter 
      new String[] {c.getColumnName(2)}, // Map the column in the HD database to... 
      new int[] {android.R.id.text1}); // The view defined in the XML template 
      hdadapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
      Spinner hdstoresspin = (Spinner) findViewById(R.id.hdstorespinner); 
      hdstoresspin.setAdapter(hdadapter1); 
      hdstoresspin.setOnItemSelectedListener(new MyOnItemSelectedListener()); 

      String text = c.getString(c.getColumnIndex(hdtable.KEY_STORENUMBER)); 

      Toast.makeText(parent.getContext(), text, Toast.LENGTH_LONG).show(); 

       } 
      startManagingCursor(c); 
      hdtable.close(); 
     } 

下面是相關DBHelper部分處理上述查詢:

public Cursor fetchRI() { 
    String RIquery = "SELECT * FROM HDStores WHERE state = 'RI' ORDER BY storenumber"; 
    return mDb.rawQuery(RIquery, null); 
    } 

UPDATE:其實我覺得OnItemSelectedListener工作正常。正在註冊點擊,但無論點擊哪個值,只有第一個值會反映在Toast消息中。再次,任何幫助將不勝感激。謝謝。

回答

2

我想這將是我錯過的一些愚蠢的東西。休息了幾天之後,我又回到工作崗位上,然後立刻跳到我身上。光標也需要最終確定。