2012-12-23 18 views
0
cursor = getContentResolver().query(GroceryItemProvider.ITEM_URI, projection, id+"="+GroceryItemTable.LIST_ID, null, null); 
adapter= new SimpleCursorAdapter(this, R.layout.list_row, cursor, from, to , 0); 
adapter.swapCursor(cursor); 

這創建一個列表與整個表而不是我用自定義值傳遞的遊標,是默認行爲?Android Simplecursoradapter沒有使用光標我正在passiing

回答

0

你是說你正在獲取所有數據列或所有數據行?如果您獲得所有欄目,請提及變量投影的價值。

cursor = getContentResolver().query(GroceryItemProvider.ITEM_URI, projection, id+"="+GroceryItemTable.LIST_ID, null, "id limit 10"); 
+0

Cursor獲取正確的行,但該適配器仍然使用表 - :如果您收到的所有行,那麼你可以通過提供的最後一個參數getContentResolver像限制行()查詢()方法。 我檢查了遊標,它只包含匹配id +「=」+ GroceryItemTable.LIST_ID的行,但適配器仍然使用表的所有行填充列表。 –

+0

在這種情況下,您應該調用 adapter.notifyDataSetChanged();在adapter.swapCursor之後。 –

+0

我試過你的建議,但它沒有解決問題,這裏是代碼 list =(ListView)findViewById(R.id.item_list); cursor = getContentResolver()。query(GroceryItemProvider.ITEM_URI,projection,id +「=」+ GroceryItemTable.LIST_ID,null,null); adapter = new SimpleCursorAdapter(this,R.layout.list_row,cursor,from,to,0); adapter.swapCursor(cursor); adapter.notifyDataSetChanged(); list.setAdapter(adapter); –