gridview - Getting Previous State of Android Fragment on Back Button -


In an Android application, I have several pieces, in one piece (piece A), I switch between two sets Number of pictures in gridview by clicking the button using the Boolean variable Th Grid View item leads to a second piece (the piece B). On pressing the back button on the piece B, the gridview inside the slice A is loaded with the default set of images, not on the images set before moving on to the next piece of piece B.

Please guide how I can reset the previous set is not the default set of images?

In the main activity, I have implemented it in Backspace:

  @BackPressed on OwnerID Public (Zero) (if Settings for SettingsFragment) LoadGridViewFragment (); Else If (the example of a piece of the singulavigagrafragragment) {Boolean keyIsfaVSL = sequence of new shared pages (read.) (SingletonClas.KIISFflection, Incorrect); if (keyIsFavSel) loadDuasListFragment (); Else loadGridViewFragment ();} and if (piece frequency Of DuasListFragment) {Booley No key ISFVSL = sequence of new shared pages (Read) (SingletonClas.KIISFFelection, Incorrect); If (keyIsFavSel) loadGridViewFragment (); and load loading DuaFragment ();} and Super.Backpress ();}   

On-cutet method of GridViewFragment.java

  @ Override public view creatives (layoutInfleter Inflator, View Group Container, Bundle Saved InstantState) {Super Sound Activity (Saved Instantstate); // Piece = New GridViewFragment (); References = inflater.getContext (); See = inflater.inflate (R.layout.fragment_gridview, container, false); Ga = New GridViewAdapter (reference); Btn_lang_Ch = (button) view.findViewById (R.id.lng_ch); Btn_Settings = (button) view.findViewById (R.id.button_settings); Favorite Deuce = (Button) view.findViewById (R.id.btn_favorite_duas); Grid Menu = (Gridview) view.findViewById (R.id.gridView1); Float scalefactor = getResources () GetDisplayMetrics () Density * 150; @SuppressWarnings ("deprecation") int number = getActivity (). GetWindowManager (). GetDefaultDisplay () GetWidth (); Int column = (int) (float) number / (float) scale factor;); GridMenu.setAdapter (GA); GridMenu.setNumColumns (column); SetRetainInstance (true); Return view; }    

You enter setRetainInstance (true) On Crate the method of slice or save and edit the appropriate code on onSaveInstanceState and onRetainInstanceState

: I usually do something like this : Override public null on @Create (bundle saved instenstate) {super.onCreate (SavedInstanceState); SetRetainInstance (true); } Private View View; @ Override public view curve (layoutInflator Inflator, View Group container, bundle savedinstenstate) {if (see == blank) {reference = investor.gate contact (); See = inflater.inflate (R.layout.fragment_gridview, container, incorrect); Ga = New GridViewAdapter (reference); Btn_lang_Ch = (button) view.findViewById (R.id.lng_ch); Btn_Settings = (button) view.findViewById (R.id.button_settings); Favorite Deuce = (Button) view.findViewById (R.id.btn_favorite_duas); Grid Menu = (Gridview) view.findViewById (R.id.gridView1); Float scalefactor = getResources () GetDisplayMetrics () Density * 150; @SuppressWarnings ("deprecation") int number = getActivity (). GetWindowManager (). GetDefaultDisplay () GetWidth (); Int column = (int) (float) number / (float) scale factor;); GridMenu.setAdapter (GA); GridMenu.setNumColumns (column); } Else {// First remove the view from ViewGroup ViewGroup parent = (ViewGroup) view.getParent (); Parent.removeView (see); } Return view; }

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -