Android fragment+ Fragmenttabhost+viewpager Switch state does not save the issue

Source: Internet
Author: User

Reprint Please specify source: http://blog.csdn.net/djy1992/article/details/46674169

@author Dujinyang

It's a rare time to write a blog.

Fragment although easy to use, but the individual still feel the pros and cons.

Most of the online said switching state, there are quite a number of problems,

There are many kinds of solutions.

The first kind of situation that is often encountered:

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 type is the ListView:

The same goes for the adapter inside the ListView,

@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 section" +position+ "test Data");((TextView) view). settextsize; return view;}

The third kind of estimate is less people encounter:

Tossing the afternoon, because of the demand relationship, you need to add Viewpager+tabhost + animation in the tab first option,

In fact, it took a long time to find that the original is the animation layer, did not save, but because it is the reason for the picture, and can not save the location,

The test has been solved for a long time.

Onpagechangelistener inside the rewritten Onpageselected,switch selector in the animation layer output by its own arg0,
Add one more option to each tab, save as a location, not in the outer record position, because there will be a bug. The position is calculated by the position of each tab, so that the position information generated by the slide can be resolved.
Hope to be useful to everyone. If there are other incurable diseases, can leave a message or add me Q.

Reprint Please specify source: http://blog.csdn.net/djy1992/article/details/46674169

Android fragment+ Fragmenttabhost+viewpager Switch state does not save the issue

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.