gpt4 book ai didi

android - 在 CursorAdapter.bindView 中遍历 Cursor

转载 作者:行者123 更新时间:2023-11-30 03:54:05 25 4
gpt4 key购买 nike

我正在使用自定义 CursorAdapter(帖子)在 ListView 中显示数据。有些帖子没有评论(我想显示相关信息)并且数据在不同的游标中(我无法加入表格,因为我按帖子 ID 分组以防止 ListView).

目前在 bindView 中,我正在遍历评论 Cursor 检查帖子 ID 是否等于当前 View 的 ID。

这个循环会减慢 UI 的速度并且应该在不同的线程中完成吗? (这增加了在回收 View 时在正确位置显示数据的复杂性)

这样做有更好的策略吗?我想到了 CursorJoiner,但我不知道如何连接这两个游标。

编辑:

例如,在我的 CurosrAdapter 实现中:

@Override
public void bindView(View view, final Context context, Cursor cursor) {
...
...
if (mCommentsCursor != null) {
mCommentsCursor.moveToPosition(-1);

int count = 0;
while (mCommentsCursor.moveToNext()) {
if (mCommentsCursor.getInt(mCommentsCursor.getColumnIndex(
COLUMN_COMMENT_POST_ID)) == postId) {

count++;
}
}

if (count > 0) {
com.setText(Integer.toString(count) + " comments");
} else {
com.setText(null);
}
}

最佳答案

我最终使用了 CursorJoinerMatrixCursor,更多关于这里的解决方案 - http://asyncindicator.blogspot.co.il/2012/12/cursorjoiner-and-matrixcursor.html

关于android - 在 CursorAdapter.bindView 中遍历 Cursor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13630965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com