CursorTreeAdapter - 返回 Childview 数据的 Groupcursor 的一部分

发布于 2024-10-19 00:38:59 字数 668 浏览 3 评论 0原文

我目前正在使用 CursorTreeAdapter 将 Curser 映射到 Android 中的 ExpandableListView。

除了 ListView 内部处理数据的方式之外,一切都工作正常。一般来说,所有数据都已经在 Cursor 中,我给了 CursorTreeAdater 的构造函数 - 甚至是 Childview 的 daa。问题是 Android 期望 getChildrenCursor 函数接收 ChildView 的数据:

@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
    db.open();
    return db.getEpisode(groupCursor.getString(0));
}

在这里您已经看到了问题。我必须返回一个光标,但我无法仅“剪切”光标中负责特定 Childview 的一个条目。相反,我想出了类似查询数据库以查找每个 ChildView 的方法。这不仅很愚蠢,因为数据已经存在(在组光标内),而且速度也相当慢。

我的问题是,是否存在某种仅克隆游标的特定条目或仅返回一个条目而不是不断查询数据库的功能。

也许我也不再使用 CursorTreeAdapter 并使用更通用的 AdapterClass 会有所帮助。

谢谢大家, 约翰内斯

I'm currently using a CursorTreeAdapter to map a Curser to an ExpandableListView in Android.

Everything works fine except from the way data is handled inside the ListView. Generally all the data is already inside the Cursor I give the Constructor of the CursorTreeAdater - even the daa for the Childview. The Problem is Android expects the data for the ChildView to be received by the getChildrenCursor function:

@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
    db.open();
    return db.getEpisode(groupCursor.getString(0));
}

Here you already see the Problem. I have to return a cursor but I'm not able to just "Cut out" the one entry in the Cursor that is responsible for the specific Childview. Instead I came up with something like querying the database for every single ChildView there is. This is not only dumb since the data is already there (inside the groupcursor) but it also ist pretty slow.

My Question would be if there is some kind of functionality of cloning only specific entries of cursors or returning only one entry instead of constantly querying the database.

Maybe I'm also off by using the CursorTreeAdapter and using a more general AdapterClass would be beneficial.

Thank you all,
Johannes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

请帮我爱他 2024-10-26 00:38:59

我目前认为这是我们自己的。

答案是从 CursorTreeAdapter 切换到 BaseExpandableListAdapter

我之前不知何故感到害怕(不知道为什么),但现在它的工作就像一个魅力。

如果有人对代码感兴趣,我可以将其发布在这里。只需发表评论

I currently figured it our myself.

The answer was to switch from a CursorTreeAdapter to a BaseExpandableListAdapter

I somehow was scared before (dunno why) but now its working like a charm.

If someone is interested in the code I can post it here. Just leave a comment

根据要求我当前的源代码。它可能需要一些清理 - 但我希望你明白这一点。如果您还有其他问题,请询问。

public class SeriesSeasonEpisodesAdapter extends BaseExpandableListAdapter {

    LayoutInflater mInflater;
    OnClickListener cbListener;
    long date;
    Cursor c;

    public SeriesSeasonEpisodesAdapter(Cursor cursor, Context context,
                    boolean autoRequery, OnClickListener cbListener) {

            this.cbListener = cbListener;

            mInflater = (LayoutInflater) context
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public boolean hasStableIds() {
            return true;
    }

    @Override
    public boolean isChildSelectable(int arg0, int arg1) {
            return false;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
            return 1;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
                    boolean isLastChild, View convertView, ViewGroup parent) {

            c.moveToPosition(groupPosition);

            % FILL convertView %

            return convertView;
    }


    @Override
    public Object getChild(int groupPosition, int childPosition) {
            return getGroup(groupPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
            // TODO Auto-generated method stub
            return 0;
    }

    @Override
    public Object getGroup(int groupPosition) {
            c.moveToPosition(groupPosition);
            return c;
    }

    @Override
    public int getGroupCount() {
            if (c == null)
                    return 0;
            return c.getCount();
    }

    @Override
    public long getGroupId(int groupPosition) {
            // TODO Auto-generated method stub
            return 0;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                    View convertView, ViewGroup parent) {

            c.moveToPosition(groupPosition);

            % FILL convertView %

            return convertView;
    }

    public void swapCursor(Cursor c) {
            this.c = c;
            notifyDataSetChanged();
    }

}

As requested my current sourcecode. It may need some cleenup - but i hope you get the point. Please ask if you have additional questions.

public class SeriesSeasonEpisodesAdapter extends BaseExpandableListAdapter {

    LayoutInflater mInflater;
    OnClickListener cbListener;
    long date;
    Cursor c;

    public SeriesSeasonEpisodesAdapter(Cursor cursor, Context context,
                    boolean autoRequery, OnClickListener cbListener) {

            this.cbListener = cbListener;

            mInflater = (LayoutInflater) context
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public boolean hasStableIds() {
            return true;
    }

    @Override
    public boolean isChildSelectable(int arg0, int arg1) {
            return false;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
            return 1;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
                    boolean isLastChild, View convertView, ViewGroup parent) {

            c.moveToPosition(groupPosition);

            % FILL convertView %

            return convertView;
    }


    @Override
    public Object getChild(int groupPosition, int childPosition) {
            return getGroup(groupPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
            // TODO Auto-generated method stub
            return 0;
    }

    @Override
    public Object getGroup(int groupPosition) {
            c.moveToPosition(groupPosition);
            return c;
    }

    @Override
    public int getGroupCount() {
            if (c == null)
                    return 0;
            return c.getCount();
    }

    @Override
    public long getGroupId(int groupPosition) {
            // TODO Auto-generated method stub
            return 0;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                    View convertView, ViewGroup parent) {

            c.moveToPosition(groupPosition);

            % FILL convertView %

            return convertView;
    }

    public void swapCursor(Cursor c) {
            this.c = c;
            notifyDataSetChanged();
    }

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