listView.isItemChecked(position)始终为true

时间:2017-09-15 08:18:39

标签: android

我想创建一个联系人列表,我可以在其中选择多个联系人。但问题是,当我点击该项目时,isItemChecked即使是新的列表也始终如此。我已将listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);应用于listView。

以下是代码。

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listView.isItemChecked(position)){
                    listView.setItemChecked(position, false);
                    personCounter--;
                    view.setBackgroundColor(Color.TRANSPARENT);
                    Log.w("item unchecked", "true");
                }else{
                    listView.setItemChecked(position, true);
                    personCounter++;
                    view.setBackgroundColor(getResources().getColor(R.color.personSelectBackground));
                    Log.w("item got checked", "true");
                }
                getSupportActionBar().setTitle("Add " + personCounter + " person.");
            }
        });

还有另一个问题。当我更改视图的背景时,它会反映多个视图(列表中的每八个视图都在变化)。我知道这是因为循环视图,但如何解决这个问题。

我还希望将此列表设为gmail列表,其中选择电子邮件会使用刻度标记修改图像。建议我任何与此相关的教程。

0 个答案:

没有答案