Maintain/Save/Restore scroll position when returning to a GridView Android
Maintain Scroll Position of Android GridView through Screen Rotation
Scroll position jumps on Android GridView
记录和恢复滚动位置-Android GridView
- static int index;
- private GridView gridView;
- @Override
- public void onResume(){
- gridView.setSelection(index);
- super.onResume();
- }
- @Override
- public void onPause(){
- index = gridView.getFirstVisiblePosition();
- super.onPause();
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_home, container, false);
-
-
- gridView= (GridView) view.findViewById(R.id.gridview);
-
- gridView.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- index = gridView.getFirstVisiblePosition();
- Intent myIntent = new Intent(getActivity(), NewsList_Activity.class);
- myIntent.putExtra("oStateItem", oStateItems.get(position));
- startActivity(myIntent);
- }
- })
- return view;
- }
复制代码 |
|