orc*_*dra 19
最后我解决了这个问题,所以我决定为其他人发布解决方案:
在我的ListFragment子类中,我声明了两个int变量来保存滚动位置
public static class MyListFragment extends ListFragment {
......................
......................
private int index = -1;
private int top = 0;
......................
Run Code Online (Sandbox Code Playgroud)
然后重写onPause()和onResume()以保存和恢复ListView滚动位置,如下所示:
@Override
public void onResume() {
super.onResume();
......................
......................
setListAdapter(mAdapter);
if(index!=-1){
this.getListView().setSelectionFromTop(index, top);
}
......................
......................
}
@Override
public void onPause() {
super.onPause();
try{
index = this.getListView().getFirstVisiblePosition();
View v = this.getListView().getChildAt(0);
top = (v == null) ? 0 : v.getTop();
}
catch(Throwable t){
t.printStackTrace();
}
......................
......................
}
Run Code Online (Sandbox Code Playgroud)
而已!!我希望这对一些人有所帮助.:)
| 归档时间: |
|
| 查看次数: |
7593 次 |
| 最近记录: |