【问题标题】:Onclick of ListView Item, check the checkox?ListView项目的Onclick,检查复选框?
【发布时间】:2016-02-10 14:17:05
【问题描述】:

我有一个列表视图,它是从带有内置资源布局的文本视图构建的 simple_list_item_multiple_choice。 像这样的语法:

ArrayAdapter 适配器 = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, internet);

如果用户单击一个项目列表,则必须选中所选项目的复选框。

我知道要实现 OnItemClickListner,但是在它之后我应该怎么做才能检查所选项目。

【问题讨论】:

  • 你可以使用 adapter.getItem(position)

标签: android listview listadapter


【解决方案1】:

你可以试试这个,来自https://stackoverflow.com/a/4590897/5193608

SparseBooleanArray.get 返回一个布尔值,但我相信您需要为列表中的每个位置检查它,例如

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 */
 }

【讨论】:

    猜你喜欢
    • 2015-11-29
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    相关资源
    最近更新 更多