android ListView:scrollTo不起作用 [英] android ListView : scrollTo doesn't work

查看:243
本文介绍了android ListView:scrollTo不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,该视图包含一个绑定到游标适配器的ListView.当光标内容更改时,我想将ListView保留在顶部,然后在我的自定义光标适配器中添加:

I have a view that contains a ListView which is binded to a cursor adapter. When The cursor content change I want to keep the ListView at the top then in my custom cursor adapter I added :

@Override
protected void onContentChanged() {
    // ...
    myListView.scrollTo(0, 0);
}

但这是行不通的.然后,我在某处阅读以将该操作排队:

but this doesn't work. Then I read somewhere to queue this action like this :

myListView.post(new Runnable() {
    public void run() {
        myListView.scrollTo(0, 0);
    }
});

但这也不起作用.

当内容更改时,如何将ListView保持在顶部?

How can I keep the ListView at the top when its content changes?

仅尝试一下,我在其onClickListener中添加了一个按钮并名为scrollTo(),但该按钮不起作用!我想念什么?

Just for try, I added a button and called scrollTo() in its onClickListener and it didn't work! What am I missing ?

推荐答案

而不是 scrollTo ,请尝试使用 setSelection(0)到达列表视图的顶部.

Instead of scrollTo, try setSelection(0) to get to the top position of list view.

这篇关于android ListView:scrollTo不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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