-1
listView.performItemClick(listView, 0, listView.getItemIdAtPosition(0));

I tried this and it works in most cases. There is one strange case: when you rotate the device, I call a performClick to e.g. Position zero, the onClickListener is called and the DetailView for the position zero is called. But if the last activated item was position 3, position 3 still continues to be highlighted. This works when I start the activity and set the first row to be activated, but not after orientation changes.

Situation: I am in Activity A in tablet mode, right site Detail view, left site list view.

Step 1: I touch the 3. list item -> the row is highlighted and the Detail view is shown.

Step 2: I rotate the tablet and I do not save anything, I do not catch orientation changes, nada-> 3. item continues highlighted.

Next step: I try to call listView.performItemClick to Position cero in the onActivityCreated Method -> effect: when the activity first starts the first row is highlighted and the Detail view is shown, when the orientation changes, onActivityCreated() is called again, performItemClick too, the onClickListener is called and the Detail view updated, but list item number 3 still continues highlighted.

Ron
  • 24,175
  • 8
  • 56
  • 97
David
  • 3,971
  • 1
  • 26
  • 65

1 Answers1

0

This happens just because view is refreshing whenever the Orientation changes. If you clicked on the listItem on the perticular orientation then it is high lighted as you wanted. But after change the orientation the view is refreshed IF you want save the state then take a look at here:

https://stackoverflow.com/a/151940/1395259

Community
  • 1
  • 1
Narendra Pal
  • 6,474
  • 13
  • 49
  • 85