Reason one: The ListView loses focus after the interface initialization is complete.
Reason two: Because the item height of the ListView is inconsistent, or the Headerview is added, the call setselection after Setadapter cannot be accurately located.
Universal Solution:
[Java]View Plaincopy
- Final ListView listview = New ListView (Getactivity ());
- Listview.post (new Runnable () {
- @Override
- public Void Run () {
- Listview.requestfocusfromtouch (); //Get Focus
- Listview.setselection (Listview.getheaderviewscount () +10);
- }
- });
If not, it's okay.
[Java]View Plaincopy
- Final ListView listview = New ListView (Getactivity ());
- Listview.postdelayed (new Runnable () {
- @Override
- public Void Run () {
- Listview.requestfocusfromtouch ();
- Listview.setselection (Listview.getheaderviewscount () +10);
- }
- },500);
Why the SetSelection of the ListView is invalid-turn