I would like to set a checkbox in a listview’s click-event.
How can I set the right checkbox?
This is my code:
listView.setOnItemLongClickListener(new OnItemLongClickListener()
{
@Override
public boolean onItemLongClick(AdapterView<?> adapter, View view,
int position, long id)
{
Checkbox checkbox = ??
checkbox.setChecked(true);
return true;
}
});
First,JavaCode in Activity:
Second,Do not forget one thing about CheckBox in layout xml, Set android:focusable=”false” to checkbox in xml , otherwise listview can`t get click event.
Third,And Most important thing,Because when listview scroll , getView() in adapter will be called unexcepted , the checkbox will be mobified unexcepted , so set checkbox status in getView() is very important , Here is my example in getView():