【问题标题】:Do I need a CursorAdapter for each table?每个表都需要一个 CursorAdapter 吗?
【发布时间】:2016-04-02 14:56:31
【问题描述】:

我有一个包含内容提供商的数据库。数据库有 6 个表。我想列出所有表格。我使用加载器,现在我有一个CursorAdapter 用于一个运行良好的表。我没有找到传递变量来识别其他表的方法。每张桌子都需要CursorAdapter 吗? 这是我的 CursorAdapter 类代码:

public class extends ActivitiesAdapter CursorAdapter {
    public ActivitiesAdapter (Context context) {
    super (context, null, 0);
}

@Override
public void BindView (View view, Context context, Cursor cursor) {
    TextView categ_list = (TextView) view.findViewById (R.id.categ_list_text);
    categ_list.setText (cursor.getString (cursor.getColumnIndex (lajesContract.CategoriasEntry.CAT_CGT)));
}

@Override
View public Newview (Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from (parent.getContext ());
    inflater.inflate return (R.layout.item_layout, null, false);
}
  }

如您所见,BindView 使用表 lajesContract.CategoriasEntry.CAT_CGT

中的数据填充列表

我怎样才能通过其他表? 谢谢。

【问题讨论】:

    标签: android database listview


    【解决方案1】:

    是的,您应该为每个表创建一个单独的适配器。

    您可能会考虑出共性,但这几乎就是 CursorAdapter 所做的。进一步重用适配器的尝试只会创建过于复杂、脆弱的代码,而没有真正的好处。

    【讨论】:

    • 感谢您的回答。十分清晰。我会继续工作。
    猜你喜欢
    • 2011-10-16
    • 1970-01-01
    • 2014-08-14
    • 2013-08-05
    • 2019-11-13
    • 2015-02-24
    • 2017-07-05
    • 1970-01-01
    • 2022-01-08
    相关资源
    最近更新 更多