ASP*_*ASP 5 android listview android-arrayadapter
我有一个listview,使用XML解析每5秒刷新一次.刷新后,列表的当前位置返回到第一个位置.有没有办法解决这个问题?
通过使用setAdapter()更新列表,Android会重置位置.请尝试更改适配器.
我不知道你正在使用哪个适配器,所以这里有两个例子.
ArrayAdapter
adapter = list.getAdapter();
if (adapter == null) {
// Create new adapter + list.setAdapter()
} else {
adapter.clear();
adapter.addAll(newData);
adapter.notify(notifyDataSetChanged());
}
Run Code Online (Sandbox Code Playgroud)
的CursorAdapter
adapter.changeCursor(newCursor);
Run Code Online (Sandbox Code Playgroud)
如果您希望列表视图在刷新时自动滚动到最后添加的条目,请使用 lv.smoothScrollToPosition(pos)其中 pos 可以是任何 int,最好是适配器的长度。
public void smoothScrollToPosition (int position)
Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7134 次 |
| 最近记录: |