【发布时间】:2015-05-14 17:34:49
【问题描述】:
在聊天应用程序中,当弹出新消息时,列表视图有两种更新方式 另一个加载更多按钮被点击了
所以我需要两种更新方式 第一个是滚动到新消息
二是停留在被点击的位置
列表视图有这些属性
<ListView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:divider="@null"
android:fadingEdge="none"
android:fastScrollEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:listSelector="@android:color/transparent"
android:smoothScrollbar="true"
android:stackFromBottom="true"
android:transcriptMode="normal" >
</ListView>
第一个条件工作正常 所以我需要在点击LoadMore时保持位置
public void updateWithOutScroll() {
final int position = chListView.getSelectedItemPosition();
Parcelable state = chListView.onSaveInstanceState();
ChatAdapter.notifyDataSetChanged();
chListView.onRestoreInstanceState(state);
chListView.post(new Runnable() {
@Override
public void run() {
chListView.setSelection(position);
}
});
}
这是让列表先滚动到底部然后再滚动到顶部
这有什么问题? 以及如何实现我的目标?
【问题讨论】: