我正在尝试从多个复选框ListView
中提取所选项目,但getcheckitempositions()
会一直返回null。
相关代码:
复选框绑定:
final ListView list = (ListView) whoView.findViewById(R.id.listView);
ArrayAdapter<String> adapter;
adapter = new ArrayAdapter(this.getActivity(), android.R.layout.simple_list_item_multiple_choice, friendList);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckedTextView checkedTextView = ((CheckedTextView) view);
checkedTextView.setChecked(!checkedTextView.isChecked());
}
});
试图拉动物品:
ListView list = (ListView) whoView.findViewById(R.id.listView);
List<String> invited = new ArrayList<String>();
SparseBooleanArray checked;
if (list != null) {
checked = list.getCheckedItemPositions(); {
for (int i = 0; i <= checked.size(); i++) {
if (checked.valueAt(i)) {
invited.add(list.getAdapter().getItem(i).toString());
}
}
}
}
我怀疑它与ListView中的getcheckitempositions()
拉动有关,而不是复选框,但我不确定如何解决这个问题。