Since ListViews set to NONE by default, in touch mode the setSelection method setSelection not have a visual effect.
To save the previous selection / visual display of the explicit selection, you must first configure the list selection mode accordingly:
listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
It is useful to read the API documents for these methods:
void android.widget.AdapterView.setSelection(int position)
Sets the currently selected item. to accessibility subclasses of accessibility that override this method must be called first override the super method.
Parameters :
position The index (starting at 0) of the selected data item.
void android.widget.ListView.setChoiceMode(int choiceMode)
Defines the selection behavior for a List. By default, lists do not have any selection behavior ( CHOICE_MODE_NONE ). By setting selectMode to CHOICE_MODE_SINGLE , the List allows up to one item to be in the selected state. By setting choiceMode to CHOICE_MODE_MULTIPLE , the list allows you to use any number of items to be selected.
Parameters :
choiceMode One of CHOICE_MODE_NONE CHOICE_MODE_SINGLE , or CHOICE_MODE_MULTIPLE
In case this is not enough (let's say you always want to show the last selection differently next to the current selection), you should save your last selected item (the data that populates the ListAdapter ) as lastSelectedItem , and in your adapter the getView method assigns another the background resource to the renderer, if it is equal to this lastSelectedItem .
If your last selection will not be updated when the selection changes, you must explicitly call the notifyDataSetChanged method in your adapter instance.
Refresh
Since your activity containing the ListView is a child of the activity that is waiting for this one result (based on the setResult(Activity.RESULT_OK,pongIntent); part setResult(Activity.RESULT_OK,pongIntent); ), the original idea is correct, the last position should be passed through the intent when the operation starts:
selectedListItem = getIntent().getIntExtra("PositionInList", -1); lvUsers.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lvUsers.setSelection(selectedListItem);
ListView.CHOICE_MODE_SINGLE will work if you stay in the same action, but you end it on every itemClick (change of choice), so additional data should be passed to the beginning of the Intent .
You can also set the previously selected background element from your adapter - mentioned above - by overriding its getView method:
lvUsers.setAdapter(new ArrayAdapter(this, R.id.counlistView, groups) { @Override public View getView(int position, View convertView, ViewGroup parent) { final View renderer = super.getView(position, convertView, parent); if (position == selectedListItem) {