2011-11-21 62 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

我想这将是我错过的一些愚蠢的东西。休息了几天之后,我又回到工作岗位上,然后立刻跳到我身上。光标也需要最终确定。