安卓:错误的项目时,过滤列表视图检查 [英] Android: Wrong item checked when filtering listview

查看:120
本文介绍了安卓:错误的项目时,过滤列表视图检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我患了同样的问题,因为这个问题:<一href="http://stackoverflow.com/questions/2487821/wrong-item-checked-when-filtering-listview-in-android">Wrong项目检查时,在安卓过滤的ListView

I'm suffering from the same issue as this question: Wrong item checked when filtering ListView in android

由于提出上述问题,我有一个持有的Hashset所有selectedIds,但我想不出如何使用它当光标再植的检查的项目。

As suggested in the above question, I have an Hashset holding all the selectedIds, but I can't figure out how to use it when the cursor is repopulating the checked items.

我的问题是唯一的化妆品 - 例如:

My issue is only cosmetic - for example:

  • 在脸谱位于在未过滤列表中的第5位。
  • 在用户搜索面子,只有脸谱出现在过滤列表中的第一个位置。
  • 在用户的检查,选择并返回到未过滤列表脸谱。
  • 选中的产品列表中,并没有脸谱(第5位)的第一个项目。

注意: 除了这个问题,一切的伟大工程。 例如,删除将删除正确的项目,因为我用的是selectedIds做到这一点(即使检查的项目是错误的)。

Note: Except this issue, everything else works great. For example, "delete" will delete the right items because I use the selectedIds to do it (even if the checked items are wrong).

单点击一个列表项:

OnItemClickListener mOnItemClickListener = new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                //gets the Bookmark ID of selected position
                    Cursor cursor = (Cursor)parent.getItemAtPosition(position);
                    String bookmarkID = cursor.getString(0);

                    boolean currentlyChecked = checkedStates.get(position);
                    checkedStates.set(position, !currentlyChecked);

                    if (!selectedIds.contains(bookmarkID)) {

                        selectedIds.add(bookmarkID);
                        selectedLines.add(position);

                    } else {

                        selectedIds.remove(bookmarkID);
                        selectedLines.remove(position);


                        }

            }
        };

里面的光标: - 这就是问题所在

这重新填充检查的项目 - 问题是,它确实是由位置(POS),什么是在过滤列表中的项目的正确的位置,是不是它在未过滤列表中的位置 - 导致错误地标记项目。

This repopulates the checked items - the problem is it does it by position (pos) and what was the right position of the item in the filtered list, is not its position in the unfiltered list - resulting in a wrongly marked item.

CheckedTextView markedItem = (CheckedTextView) row.findViewById(R.id.btitle);
markedItem.setChecked(checkedStates.get(pos));

请问AP preciate任何帮助!

Would appreciate any help!

推荐答案

解决这个问题。 正如建议在我加入到我的问题,当你填充复选框,其他列表/应的Hashset确定作为托运或不在于是否标示的项目。

Solved the issue. As suggested in the question I added to mine, when you populate the checkboxes, the other List/Hashset should determine whether to mark item as checked or not.

使用我的code:

//first you will need to get the current item ID
String bookmarkID = cursor.getString(0);

//Then, check if the current ID is in the selectedIds hash/list
//If true - mark current item view as checked, else - uncheck.
        CheckedTextView markedItem = (CheckedTextView) row.findViewById(R.id.btitle);
        if (selectedIds.contains(new String(bookmarkID))) {
            markedItem.setChecked(true);

        } else {
            markedItem.setChecked(false);
}

真希望这将帮助任何人! :)

Really hope this will help anyone! :)

这篇关于安卓:错误的项目时,过滤列表视图检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆