The context: I want to have a ListView that wouldn't receive focus (e.g. won't highlight row when user touches it). Yet each row widget has it's own OnClickListener. Here's what I specify in layout xml:
android:choiceMode="none"
android:focusableInTouchMode="false"
android:focusable="false"
The ListView still behaves exactly the same. Could someone please explain
TIA.
Although you specified in the xml you could try specifying in code as well. Although i'm not sure you can set a list to not focusable and still have the list be scrollable and it's clickable.
after your setContentView...
myListView.setFocusableInTouchMode(false);
You could try and inherit from the view as well and then add a little debugging code in the interim to help you find when the list actually has focus.
myListView.setOnFocusChangeListener(new OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus)
{
v.setBackgroundColor(hasFocus ? Color.GRAY : Color.BLACK);
}
});
myListView.setClickable(true);
The list receiving focus is different than the selected row not highlighting. The list gets focus whenever a user is in it. The best a ListView can do is report an int for whatever the user has selected. I'm not sure how each row widget has it's own ClickListener. There are no row widgets that I am aware of. The onListItemClick belongs to the ListView.
I havent been able to figure it out yet, but between android:listSelector and android:background and adjusting the alpha channels I figure there would be a way to make a selection look just like a non-selected row.
android:listSelector="#8fff" makes it so just the foreground changes on selection.
It seems like android chooses the non-selected foreground on its own, which is making this hard. I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With