在激活i'm only able to select 2 items
到ListView
之后,有人知道Multiple Choice
的原因。
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
//Activate CHOICE_MODE_MULTIPLE
multipleActivated = true;
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setItemChecked(position, true);
Log.w("Multiple Selection", "Activated");
return true;
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (multipleActivated == false) {
//Perform normal click and call new intent
.....
} else {
//set the clicked item to be checked since the Multiple Selection is activated
listView.setItemChecked(position, true);
Log.w("Selection", String.valueOf(position));
}
}
});
正如你在我的代码中看到的那样,我只想在LongPress执行后激活Multiple Choice Mode
,这个确定并且工作正常,但是我可以选择2个项目,在第3个选择第一个选择的项目只是取消选择。我不知道为什么。有人可以帮我吗?谢谢!