Android fragment + FragmentTabHost + viewpager switchover status not saved
@ Author dujinyang
It is rare to have time to write a blog.
Although fragment is easy to use, I still think it has advantages and disadvantages.
Switching status is often said on the Internet, which has many problems,
There are many solutions.
The first common situation:
if(rootView == null)rootView = inflater.inflate(R.layout.fragment_home, container,false);ViewGroup parent = (ViewGroup) rootView.getParent(); if (parent != null) parent.removeView(rootView); initView(rootView); return rootView;
The second is LISTVIEW:
Similarly, in the listview adapter,
@ Overridepublic View getView (int position, View convertView, ViewGroup parent) {View view = convertView; if (view = null) {view = new TextView (getActivity (). getApplicationContext ();} (TextView) view ). setText (this is the + position + test data); (TextView) view ). setTextSize (20); return view ;}
The third estimate is that few people encounter:
After one afternoon, you need to add ViewPager + Tabhost + animation in the first option of the TAB due to the demand relationship,
In fact, it took a long time to find that the animation layer was not saved, but it was impossible to save the location because it was an image,
It has been tested for a long time.
OnPageSelected rewritten in OnPageChangeListener. In the switch selector, the animation layer output comes with arg0,
Add one more option for each tab, Which is saved as a location and cannot be located in the outer record because of a BUG. The original position is calculated based on the position of each tab, which solves the location information generated during sliding.
I hope it will be useful to you. If you have other problems, leave a message or add me Q.
Reprinted please indicate the source: http://blog.csdn.net/djy1992/article/details/46674169