Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set ListView Scroll position to bottom in android?

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?

like image 958
Dinesh Anuruddha Avatar asked Jan 27 '14 05:01

Dinesh Anuruddha


1 Answers

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);
like image 72
RVG Avatar answered Nov 15 '22 09:11

RVG