How to set ListView Scroll position to bottom in android?
18,949
Solution 1
try this. the below code is working fine for me.
give time delay 500 for load listview then call setselection method.
commentslistview.postDelayed(new Runnable() {
@Override
public void run() {
commentslistview.setSelection(commentsarraylist.size());
}
}, 500);
Solution 2
Did you set these in your ListView?
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
Solution 3
listView.setAdapter(adapter);
listView.setSelection(position);
Solution 4
:D I just set:
mListView.setSelection(adapter.getCount() - 1);
And my Layout
<ListView
android:id="@+id/tb_body"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
android:stackFromBottom="true"
tools:ignore="NestedScrolling" >
</ListView>
SET
android:choiceMode="singleChoice"
android:stackFromBottom="true"
Hope it works fine with you.
Solution 5
Try this
srollView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mScrollView.post(new Runnable() {
@Override
public void run() {
scrollView.smoothScrollTo(0,scrollView.getBottom());
}
});
}
});
Comments
-
Dinesh Anuruddha almost 2 years
I know this question is asked several times before but my situation is bit different from other questions.
I have a listview and initially i want to set the scroll position to the bottom of the list.
I have try 2 ways.
1st one
mCommentListView.setSelection(mAdaptor.getCount()-1);
2nd one
mCommentListView.post(new Runnable() { @Override public void run() { mCommentListView.setSelection(mAdaptor.getCount()-1); } });
So my problem is both of above code working properly with the emulator but it is not working with the real device.
What have i missed?