views:

651

answers:

1

I have a simple listview and listadapter setup as follows:

listAdapter = new ArrayAdapter<MyDomainObject>(this, android.R.layout.simple_list_item_1, listOfDomainObjects);
listView.setAdapter(listAdapter);

The user makes a selection on the list which takes them to another activity. From the new activity they can click their selection which returns them to the activity with the above list. I want to highlight the previous selection made. I currently find the matching list entry and call:

listView.setSelection(matchIndex);

This brings their previous selection to the top of the list. Is it possible to highlight (in that default orange) the previous selection. I have tried several approaches with no luck.

+2  A: 

What you have is fine. However, the determination of whether the selection is "highlighted" is determined on whether the user was using the touchscreen. If they have used the touchscreen more recently than the trackball/D-pad/whatever, the device is in "touch mode" and selection highlights are not shown.

CommonsWare
Why aren't selections shown without the trackball/D-Pad? That is confusing to me. Can you site the documentation for an explanation?
mobibob
@mobibob: http://developer.android.com/resources/articles/touch-mode.html
CommonsWare
Ah ... I thought I knew the UI based on the method names and did not understand why I could not control the selection or receive notification of selection (no trackball or d/pad on the phone under test). I have now read this chapter and will review often.
mobibob