android - How to refresh a Fragment with a View object -
i'm building classic menu/detail fragment tablet activity.
my detail fragment graph generate external library. libray giving me intent or view of graph.
when i'm clicking on menu want refresh graph.
this activity code :
public class myactivity extends fragmentactivity { context context; graphical graphical; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); context = this; setcontentview(r.layout.fragment_suivi_conso_graph); } /** * called when clicking on menu fragment */ public void onchoosegraph(urlaction urlaction){ graphfragment graphfragment = (graphfragment) getsupportfragmentmanager().findfragmentbyid(r.id.graph_fragment); if (graphfragment == null || !graphfragment.isinlayout()) { intent intentgraph; intentgraph = graphical.executeforintent(this, urlaction); startactivity(intentgraph); } else { view graphview = graphfragment.loadgraph(urlaction); // don't know view ! } } this detail fragment code :
public class graphfragment extends fragment { private context context; private graphical graphical; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { super.oncreate(savedinstancestate); context = this.getactivity(); graphical = new graphical(); view graphview = null; graphview = graphical.executeforview(context, urlaction.conso_weeks); return graphview; } public view loadgraph(urlaction urlaction) { log.d("graphfragment","[loadgraph] start"); view graphview = graphical.executeforview(context, urlaction); //this graphview contains graph want display in graphfragment return graphview; } } i don't know if can reload fragment view loadgraph function of fragment. or need on activity onchoosegraph function.
in both case, don't know how refresh.
i found solution :
on detail fragment : graphfragment, here proper loadgraph methode :
public void loadgraph(urlaction urlaction) { log.d(tag,"[loadgraph] start, urlaction : " + urlaction); view graphview = null; try { graphview = graphical.executeforview(context, urlaction); } catch (exception e) { log.e(tag, "[loadgraph] error during parsing : "+e.getmessage()); e.printstacktrace(); if(e.getmessage().equals(xmlparsersuivitconso.xml_is_error)){ toast.maketext(context, getstring(r.string.checkyouparameters), toast.length_long).show(); intent intentsettings = new intent(context, settingsactivity.class); startactivity(intentsettings); getactivity().finish(); } } setfragmentcontentview(graphview); } void setfragmentcontentview(view view) { linearlayout.layoutparams layoutparams = new linearlayout.layoutparams(viewgroup.layoutparams.fill_parent, viewgroup.layoutparams.fill_parent); mrootlayout.removeallviews(); mrootlayout.addview(view, layoutparams); } and on activity myactivity using following code call loadgraph :
public void onchoosegraph(urlaction urlaction){ graphfragment graphfragment = (graphfragment) getsupportfragmentmanager().findfragmentbyid(r.id.graph_fragment); // on essaye de récupérer notre fragment. // s'il n'est pas présent, on le crée en lançant son activity if (graphfragment == null || !graphfragment.isinlayout()) { intent intentgraph; try { intentgraph = graphical.executeforintent(this, urlaction); startactivity(intentgraph); } catch (exception e) { log.e(tag, "[onlistitemclick] error during parsing : "+e.getmessage()); e.printstacktrace(); if(e.getmessage() == null || e.getmessage().equals(xmlparsersuivitconso.xml_is_error)){ toast.maketext(this, getstring(r.string.checkyouparameters), toast.length_long).show(); intent intentsettings = new intent(this, settingsactivity.class); startactivity(intentsettings); finish(); return; } } } else // sinon on met à jour le choix de l'utilisateur { graphfragment.loadgraph(urlaction); } i hope 1 !
Comments
Post a Comment