我遇到了ViewPager的问题,我的ListView正在丢失它的滚动位置.
使用以下命令可以轻松地存储和恢复ListView的状态:
@Override public View onCreateView (LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { View v = inflater.inflate(R.layout.frag_cool_things,container,false); AdvListView listView = (AdvListView) v.findViewById(R.id.lv0); listView.setOnItemClickListener( mOnListItemClicked ); if (null != savedInstanceState) { listView.onRestoreListViewInstanceState(savedInstanceState.getParcelable("list_state")); } mListView = listView; return v; } @Override public void onSaveInstanceState (Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable("list_state",mListView.onSaveListViewInstanceState()); }
然而问题是当片段被刷过onDestroyView()被调用但从不调用onSaveInstanceState(Bundle outState).
旋转屏幕,这样恢复ListView状态就好了,但刷卡我无法弄清楚如何正确恢复列表.