如何将 GridView 绑定到自定义 ContentProvider
我正在尝试将客户 ContentProvider 绑定到持有 GridView 的活动,
String[] projection = { SAppsDatabase.ID, SAppsDatabase.COL_APP_TITLE};
String[] uiBindFrom = { SAppsDatabase.COL_APP_TITLE };
int[] uiBindTo = { R.id.title };
Cursor apps = managedQuery(
MyProvider.CONTENT_URI, projection, null, null, null);
GridView gridview = (GridView) findViewById(R.id.gridview);
CursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.grid_app_list, apps,
uiBindFrom, uiBindTo);
gridview.setAdapter(adapter);
但这不起作用。
我设法通过执行与上面相同的操作并将其绑定到 ListActivity 并设置: setListAdapter(适配器);
I'm trying to bind a customer ContentProvider to my activity that holds a GridView
String[] projection = { SAppsDatabase.ID, SAppsDatabase.COL_APP_TITLE};
String[] uiBindFrom = { SAppsDatabase.COL_APP_TITLE };
int[] uiBindTo = { R.id.title };
Cursor apps = managedQuery(
MyProvider.CONTENT_URI, projection, null, null, null);
GridView gridview = (GridView) findViewById(R.id.gridview);
CursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.grid_app_list, apps,
uiBindFrom, uiBindTo);
gridview.setAdapter(adapter);
This is not working.
I manage to bind it to a ListActivity by doing the same as above, and setting:
setListAdapter(adapter);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对于 GridView 不起作用,因为名称表明它是视图网格
,但您为其提供了一个没有多大意义的光标适配器。
请查看此示例
如果您想提供自定义, 那么你将拥有扩展适配器并返回适配器中的视图内容。
This will not work for a
GridView
as the name indicates it is a grid of viewsbut you are providing it a cursor adapter which doesn't make much sense.
Take a look at this sample
If you want to provide a custom adapter then you will have extend adapter and return the view content in the adapter.