Wednesday, January 22, 2014

About Fragment of switching state preservation


            
My activity has a back button, the event added a getFragmentManager () popBackStack ();.
Then put new activity in a fragmentA, fragmentA have a listview, after some operations have been dynamically populate some data in fragmentA click a button, I passed
FragmentTransaction transaction = getFragmentManager () beginTransaction ();.
FragmentB fragment = new FragmentB ();
transaction.replace (R.id.main_container_bottom, fragment);
transaction.addToBackStack (null);
transaction.commit ();
To fragmentB, and then press the Back button to return to the fragmentA, why is not the state of A before saving? Again to load the interface, load data flow away again?
Reply:
I also do this thing, people who have not done to answer under
Reply:
fragment of the same state saving and activity through saveinsatance saved. . .
Reply:
I also looked at onSaveInstanceState relevant information, whether upstairs to the point of simple code illustrates the process under
Reply:
onSaveInstanceState still want to preserve their own content to be saved, so it is quite troublesome. Why popBackStack, this method removes the top of the stack after the fragment, the remaining fragment of it is refreshing
Reply:
I have to give up the use of fragment, this thing is only suitable for fixed stuff displayed because onCreateView always be invoked, each call will brush over the interface, you need to own the data and then set into a small amount of data can also operate a large number of This process is very accurate data, and then study free
Reply:
references, 5th Floor iMaxb reply:
I have abandoned the use of fragment, this thing is only suitable for display fixed things, because onCreateView always be invoked , each call will brush over the interface, you need to own the data and then set into a small amount of data can also operate this process large amounts of data very unhappy, empty and then study
normal ah put data . TabActivity not do the same!
Reply:
I also encountered the same problem, I flipped on the screen when you can save the state, but switching to another fragment when it can not save, and in the end how is it ~ ~ ~
Reply:
FragmentManager fm = getSupportFragmentManager ();
FragmentTransaction ft = fm.beginTransaction ();
for (int i = 0; i Fragment userFragment = fm.findFragmentByTag (TabTag (i));
Fragment fragment = null;

if (userFragment! = null)
fragment = userFragment;
else {
fragment = mFragments.get (i); / / mFragments is stored in your fragment instance of LIST
}
if (i == index) {
if (! fragment.isAdded ()) {
ft.add (R.id.content, fragment, TabTag (i)) ;/ / third parameter plus Tag
}
} Else {
if (fragment.isAdded ()) {
ft.remove (fragment);
ft.addToBackStack (null);
}
}
}
ft.commit ();
Reply:
I have encountered. Always onCreateView, how to break?
Reply:
Same. . . . . . . . . . . . . .
Reply:

Seeking the truth ~
Seeking relief ~ ~ ~ ~ ~ ~ ~
Reply:
The same truth-seeking relief Xiangqiu
Reply:
 
transaction = getSupportFragmentManager () beginTransaction ();.

if (fragment! = null) {
transaction.hide (fragment);
}

fragment = fragments.get (folder);

if (fragment == null) {
fragment = new MailFragment ();

transaction.add (R.id.frameLayout, fragment);
fragments.put (folder, fragment);
}
transaction.show (fragment);
transaction.commit ();

Reply:
reference to the 13th floor macjie reply:
 
transaction = getSupportFragmentManager () beginTransaction ();.

if (fragment! = null) {
transaction.hide (fragment);
}

fragment = fragments.get (folder);

if (fragment == null) {
fragment = new MailFragment ();

transaction.add (R.id.frameLayout, fragment);
fragments.put (folder, fragment);
}
transaction.show (fragment);
transaction.commit ();

Can you give the full code number?
Reply:

replace (), the front of the Fragment will then perform again onCreateView () inIn order not to onCreateView (), with the add (), to control their own hide () or show ()

No comments:

Post a Comment