0

我有一个微调从sqlite填充值(类别表中的类别)现在我需要一个选择查询检索项目到列表视图。这样在微调器选择改变列表视图值也会改变。项目从另一个表来(项目).cid在项目表和CID外键是在类表的主键我试过,但显示空列表视图....选择查询加载微调选择项目

String select = "SELECT " + 
      Support.KEY_INAME + " FROM " 
      + Support.TABLE_ITEMS + " LEFT JOIN " 
      + Support.TABLE_CAT + " ON " 
      + (Support.TABLE_ITEMS + "." + Support.KEY_CID) +" = " 
      + (Support.TABLE_CAT + "." + Support.KEY_CID) 
      + " WHERE " + Support.TABLE_CAT + "." + Support.KEY_CID + " =?"; 

这是我选择的微调和加载列表视图数据代码...

spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
     @Override 
     public void onItemSelected(AdapterView<?> parent, View view, final int position, long id) { 

      Spinner spinner = (Spinner)parent; 

      if (spinner.getId() == R.id.spinner1) { 

       dbRepo = new DBRepo(getApplicationContext()); 
       final List<Support> list = dbRepo.getItems1(); 
       adapter = new Custom(Category.this, R.layout.view_entry, list); 
       adapter.setDropDownViewResource(android.R.layout.simple_list_item_1); 

       adapter.notifyDataSetChanged(); 
       lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 
       lv.setAdapter(adapter); 

}

+0

我已经提到,这是debuged代码...调试深藏不露的列表视图 –

+0

后你肯定问题在于选择不晚? –

+0

是的becase当我设置最后Support.KEY_CID +“= 0”显示项目有cid 0 –

回答

0

上面的查询是真实的,或者我解决使用这两个查询

String selectQuery = "SELECT * FROM " + TABLE_ITEM + " WHERE " + KEY_CID + " ='" + cid + "'"; 
    Cursor c = db.rawQuery(selectQuery, null); 
我的问题

OR

Cursor c = db.rawQuery("SELECT * FROM item_table WHERE _CategoryID =? " ,new String[]{cid}, null); 

和改变也改变了代码spinner.setonItemSelected这样

spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
     @Override 
     public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 

       handler = new DBSQLite(getBaseContext()); 
       String selected = (String) parent.getItemAtPosition(position); 
       // Toast.makeText(getApplicationContext(), selected, Toast.LENGTH_SHORT).show(); 
       String cid = handler.getCid(selected); 
       final ArrayList<Support> item = handler.getItems(cid); 
       adapter = new CustomAdapter(AvailableItems.this, R.layout.available_view, item); 
       lv.setAdapter(adapter); 
       adapter.notifyDataSetChanged(); 
     } 

     @Override 
     public void onNothingSelected(AdapterView<?> parent) { 

     } 
    });