2012-12-23 34 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); –