Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the focus on the last element in a list view in android

I am loading elements in a ListView at runtime and asking user if he wants to load more elements on a button click.What i want to achieve is that the focus should be on the last element of the listview and not on the first element.

like image 438
Shabbir Panjesha Avatar asked Nov 15 '11 10:11

Shabbir Panjesha


2 Answers

If you want to show the list view from the bottom use below thing .

ListView

android:stackFromBottom="true" />

Its working for me.

like image 187
S HemaNandhini Avatar answered Nov 11 '22 19:11

S HemaNandhini


You need to use these parameters in your list view:

Scroll lv.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

Set the head of the list to its bottom lv.setStackFromBottom(true);

You can also set these parameters in XML, eg. like this:

ListView
...
android:transcriptMode="alwaysScroll"
android:stackFromBottom="true" />
like image 26
abhishek Avatar answered Nov 11 '22 18:11

abhishek