How can I set a long-clicked item as selected?
This does not work (item does not maintain selected when clicked):
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
listView.setSelection(position);
return true;
}
});
If you’re trying to use a multi-select list, make sure you flag it as such:
If it’s a single-select list, you still need to flag it as a “choice mode” list, as opposed to one where clicking just performs an action, not selects the item.
And since you’ve got the view you want to select being passed in as a parameter, you don’t need to set by position, you can set by the view instead, like so: