我正在尝试删除所选的已检查项目但是从代码中收到此错误。请帮忙。
submit.setOnClickListener(new View.OnClickListener() { //set action after clicking submit
@Override
public void onClick(View view) { //delete checked items and refresh
SparseBooleanArray checkedItemPositions = lview.getCheckedItemPositions();
int itemCount = lview.getCount();
for(int i=itemCount-1; i >= 0; i--){
if(checkedItemPositions.get(i)){
adapter.remove(hangerlist.get(i));
}
}
checkedItemPositions.clear();
adapter.notifyDataSetChanged();
for (int i = 0; i < lview.getChildCount(); i++) { //remove checkbox after deleting
lview.getChildAt(i).findViewById(R.id.checkDelete).setVisibility(View.INVISIBLE);
}
btn.setVisibility(View.INVISIBLE); //remove submit and cancel button after deleting
}
});
答案 0 :(得分:0)
SparseBooleanArray checkedItemPositions = lview.getCheckedItemPositions();
此行返回null SparseBooleanArray。 您需要检查列表视图是否已选中项目位置&#39;,尝试添加断点或发布更多代码来初始化lView组件。