相关疑难解决方法(0)

调用notifyDataSetChanged后,在ListView中保留位置

我正在使用OnScrollListener在用户滚动到底部时动态地将项添加到ListView.在我将数据添加到适配器并调用notifyDataSetChanged后,ListView返回到顶部.理想情况下,我想保留ListView中的位置.关于我应该怎么做的任何想法?

android listview

42
推荐指数
2
解决办法
3万
查看次数

Android ListView将项目添加到顶部而没有列表视图滚动

我有一个listView,我想在列表视图的顶部添加新项目,但我不希望列表视图滚动其内容.我希望用户在添加新项目之前查看他正在查看的相同项目.

这是我向ListView添加新项目的方法:

this.commentsListViewAdapter.addRangeToTop(comments);
this.commentsListViewAdapter.notifyDataSetChanged();
Run Code Online (Sandbox Code Playgroud)

这是addRangeToTop方法:

public void addRangeToTop(ArrayList<Comment> comments)
{
    for (Comment comment : comments)
    {
        this.insert(comment, 0);        
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的listView:

<ListView
    android:id="@+id/CommentsListView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/AddCommentLayout" 
    android:stackFromBottom="true" >        
</ListView>
Run Code Online (Sandbox Code Playgroud)

我想要做的是在用户滚动到顶部时加载旧注释.

谢谢您的帮助.

android listview scroll

23
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×2

listview ×2

scroll ×1