I've got a silly little problem. I've registered a ListFragment
both as OnItemClickListener
and OnItemLongClickListener
of its own ListView
.
When the onItemClick
event is called, an intent for the detail view activity of that item is started, no problems there.
When the onItemLongClick
event happens, I want to accomplish the following things:
- Create a CAB
- Keep the long-pressed item selected
Code:
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if(this.cabMode != null)
return false;
this.cabMode = getActivity().startActionMode(editModeCallback);
view.setSelected(true);
return true;
}
The CAB will show, however, the selection won't stay with the item.
Some bits and pieces, in case they are relevant: I've read about fixing this issue with calls to view.requestFocusFromTouch()
or using listView.setItemChecked()
, but that didn't work for me. Also, the views for the list items are instanced from a custom layout, but don't have any custom event listeners attached.
Any help is appreciated. Thx!
listView.setItemChecked()
takes a position argument, but calling it doesn't have an effect. – BarhamListView.setChoiceMode(...)
? If you don't find a way to fix this, you can always do the selection manually like here goo.gl/7aQAn – NavellistView.setItemChecked()
andview.setSelected()
, but still no effect. I'll have a look at the Sherlock code, however I would think, that what I'm trying to do is so basic that there must be an easy way to accomplish it. – Barham