java - How to Update a Fragment From PreferenceActivity? -
my main activity has several fragments, 1 of has listview or gridview. have preferenceactivity configures how app looks , functions, in particular whether display list or grid.
when list/grid view setting changed in preference activity want reflect change in fragment (located in app's main activity). how do separate activity? (in cast preference activity).
edit- managed accomplish using onresume() callback check if relevant preference changed, , if there change:
public void onresume() { super.onresume(); sharedpreferences settings = getactivity().getsharedpreferences("settings", 0); boolean layout = settings.getboolean("layout", false); if (layout == true) { listview.setvisibility(view.visible); gridview.setvisibility(view.gone); } else { listview.setvisibility(view.gone); gridview.setvisibility(view.visible); } }
you can start preferenceactivity
using startactivityforresult
return result in mainactivity.in onactivityforresult() update view.
protected void onactivityresult(int requestcode, int resultcode, intent data) { if(resultcode == result_ok){ //update view. } }//onactivityresult
Comments
Post a Comment