我正在使用OnScrollListener在用户滚动到底部时动态地将项添加到ListView.在我将数据添加到适配器并调用notifyDataSetChanged后,ListView返回到顶部.理想情况下,我想保留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)
我想要做的是在用户滚动到顶部时加载旧注释.
谢谢您的帮助.