views:

2492

answers:

2

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 plz explain

  1. the interrelation between the three
  2. what's the right way to create a ListView that doesn't receive focus?

TIA.

A: 

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.

Will
+1  A: 

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);
Quintin Robinson