Android fragment + FragmentTabHost + viewpager switchover status not saved

Source: Internet
Author: User

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

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.