how to get a list item to remain selected? Android deselects

Put your problem here if it does not fit any of the other categories.

how to get a list item to remain selected? Android deselects

Postby Anil » Wed Mar 05, 2008 8:10 pm

Normally in a UI when a list item is selected, one expects it to
remain selected.
Unusually, in Android, after selecting an item, Android immediately de-selects it.

I implemented interface OnItemSelectedListener and tried to reselect
it again, but it doesn't.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  public void onItemSelected(AdapterView parent, View v, int position,
  2.  
  3. long id) {
  4.  
  5.                 Log.v(TAG, "onItemSelected");
  6.  
  7.                 v.setSelected(true);
  8.  
  9.         }
  10.  
  11.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Does anyone know a solution?
thanks,
Anil
Anil
Developer
Developer
 
Posts: 44
Joined: Fri Jan 04, 2008 9:15 pm

Top

Postby plusminus » Wed Mar 05, 2008 8:23 pm

Hello Anil,

you are probably looking for requestFocus() :?:

Android differs focus and selection.
I.e. you can have your cursor in an EditText AND check a CheckBox with touch, without loosing the focus to EditText .

(I'm not really sure what is selection and what is focus ;) but its not the same)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Anil » Wed Mar 05, 2008 9:12 pm

Hi plusminus,
I tried requestFocus - it does not work.
See sample ApiDemos/List8 in the emulator.
create a list of photos and click on one. It briefly flashes yellow like a button.
But this is not a button so it is weird behavior IMHO.
background: I want the user to work on a list item, and to know which item he is working on, I want some visual indicator.
Perhaps I shall change the color of the item explicitly.
thanks,
Anil



plusminus wrote:Hello Anil,

you are probably looking for requestFocus() :?:

Android differs focus and selection.
I.e. you can have your cursor in an EditText AND check a CheckBox with touch, without loosing the focus to EditText .

(I'm not really sure what is selection and what is focus ;) but its not the same)

Regards,
plusminus
Anil
Developer
Developer
 
Posts: 44
Joined: Fri Jan 04, 2008 9:15 pm

Postby Anil » Wed Mar 05, 2008 10:43 pm

Anil wrote:Perhaps I shall change the color of the item explicitly.


unfortunately, changing the background color doesn't work for some reason. Can you suggest a solution?
Anil
Developer
Developer
 
Posts: 44
Joined: Fri Jan 04, 2008 9:15 pm

Postby Anil » Thu Mar 06, 2008 8:24 pm

Anil wrote:
Anil wrote:Perhaps I shall change the color of the item explicitly.


unfortunately, changing the background color doesn't work for some reason. Can you suggest a solution?


I simply used a checkbox button with each list item :(
Anil
Developer
Developer
 
Posts: 44
Joined: Fri Jan 04, 2008 9:15 pm

Postby nk » Fri Mar 14, 2008 4:11 pm

did you solve this problem?
nk
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jan 29, 2008 3:23 pm

Top

Postby Anil » Fri Mar 14, 2008 4:42 pm

nk wrote:did you solve this problem?

yes, the explanation is above.
Anil
Developer
Developer
 
Posts: 44
Joined: Fri Jan 04, 2008 9:15 pm

Postby ferobert » Wed Apr 09, 2008 10:40 am

I had this problem myself, and eventually I learned that the real problem for visually selecting a row, has to do with touchmode vs keymode. If you are in touch mode, Android considers there is no need to highlight the row. You can change this default behavior with:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. getListView().setFocusableInTouchMode(true);
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


After this, using setSelection() will also visually select the row you indicate. More info here:
http://groups.google.com/group/android- ... dda862f864

Robert
ferobert
Freshman
Freshman
 
Posts: 6
Joined: Sun Apr 06, 2008 6:22 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 19 guests