我正在创建一个带有复选框的ListView,该复选框最初是Visibility:Gone。我想长按一个项目时查看所有复选框,但有些项目没有显示复选框,当我滚动时它会改变。我想使它与messagin应用程序一样,我可以通过选择多个复选框删除多个项目。
lists[0].setLongClickable(true);
lists[0].setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
CheckBox selectAll = (CheckBox) findViewById(R.id.selectAll);
selectAll.setVisibility(View.VISIBLE);
int count = lists[0].getChildCount();
int adapter = myAdapter[0].getCount();
Toast.makeText(getBaseContext(), Integer.toString(adapter), Toast.LENGTH_LONG).show();
for (int i = 0; i < adapter; i++) {
View v = (View) lists[0].getItemAtPosition(i);
CheckBox box = (CheckBox) v.findViewById(R.id.checkBoxSelect);
box.setVisibility(View.VISIBLE);
}
return true;
}
});
myAdapter[0].notifyDataSetChanged();
lists[0].setAdapter(myAdapter[0]);