Listview 更新列表后滚动到列表末尾 [英] Listview Scroll to the end of the list after updating the list

查看:24
本文介绍了Listview 更新列表后滚动到列表末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我使用 listAdapter 更新列表视图后,我想确保列表一直滚动到底部,以便它显示在列表中输入的最后一个元素.我该怎么做?

I would like to make sure that the list is scrolled all the way to the bottom, after I have updated the listview by using listAdapter, so that it displays the last element entered in the list. How can I do this ?

我试过了,但没有运气:

I tried this but no luck:

lv.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

谢谢

推荐答案

假设您知道列表数据何时发生更改,您可以通过将列表选择设置为最后一行来手动告诉列表滚动到底部.类似的东西:

Supposing you know when the list data has changed, you can manually tell the list to scroll to the bottom by setting the list selection to the last row. Something like:

private void scrollMyListViewToBottom() {
    myListView.post(new Runnable() {
        @Override
        public void run() {
            // Select the last row so it will scroll into view...
            myListView.setSelection(myListAdapter.getCount() - 1);
        }
    });
}

这篇关于Listview 更新列表后滚动到列表末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆