0

after multiple try's, i'm using "mListView.setSelection(0);" to select the first row in my ListView when the list appears. But dunno why its not working. So how can I let the first row always clicked? Because in my application i have a listview on left side and a webview on right side. So i need that when my app launchs, the first row always selected so the webview loads the details of the first element per default. The data of the listView are loaded using a cursor Adapter that communicates with an SQLite Database.

This is a part of my code : code

Anthony
  • 189
  • 1
  • 3
  • 16

2 Answers2

0

Try setting up an OnGlobalLayoutListener to your ViewTreeObserver, which sets the selection as soon as the layout is set. (Remember to remove the listener as soon as it's called the first time to avoid repeated calls.)

Check the android sources whether setSelection(int) handles unpopulated lists right.

Bondax
  • 3,143
  • 28
  • 35
0

You can try using smoothScrollToPosition(int position) it should work for you.

mListView.smoothScrollToPosition(0);
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242