如何将 GridView 绑定到自定义 ContentProvider

发布于 2024-11-28 13:29:27 字数 685 浏览 7 评论 0原文

我正在尝试将客户 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自找没趣 2024-12-05 13:29:27

这对于 GridView 不起作用,因为名称表明它是视图网格

GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. 
The grid items are automatically inserted to the layout using a ListAdapter.

,但您为其提供了一个没有多大意义的光标适配器。

请查看此示例

如果您想提供自定义, 那么你将拥有扩展适配器并返回适配器中的视图内容。

This will not work for a GridView as the name indicates it is a grid of views

GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. 
The grid items are automatically inserted to the layout using a ListAdapter.

but 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文