单击 ListView 项目,选中复选框?
Onclick of ListView Item, check the checkox?
我有一个列表视图,它是从具有内置资源布局的文本视图构建的 simple_list_item_multiple_choice。
像这样的语法:
ArrayAdapter 适配器 = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, internet);
如果用户单击项目列表,则必须选中所选项目的复选框。
我知道要实现OnItemClickListner,但是实现之后我应该怎么做才能检查选中的项目。
你可以试试这个,参考自。
SparseBooleanArray.get returns 一个布尔值,但我相信您需要检查列表中的每个位置,例如
int len = listView.getCount();
SparseBooleanArray checked = listView.getCheckedItemPositions();
for (int i = 0; i < len; i++)
if (checked.get(i)) {
String item = cont_list.get(i);
/* do whatever you want with the checked item */
}
我有一个列表视图,它是从具有内置资源布局的文本视图构建的 simple_list_item_multiple_choice。 像这样的语法:
ArrayAdapter 适配器 = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, internet);
如果用户单击项目列表,则必须选中所选项目的复选框。
我知道要实现OnItemClickListner,但是实现之后我应该怎么做才能检查选中的项目。
你可以试试这个,参考自。
SparseBooleanArray.get returns 一个布尔值,但我相信您需要检查列表中的每个位置,例如
int len = listView.getCount();
SparseBooleanArray checked = listView.getCheckedItemPositions();
for (int i = 0; i < len; i++)
if (checked.get(i)) {
String item = cont_list.get(i);
/* do whatever you want with the checked item */
}