java - how to access a Fragment from the inner AsyncTask -
i have fragment
, inner asynctask
loads text:
public class textreaderfragment extends fragment { loadtexttask task = null; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { setretaininstance(true); task=new loadtexttask(); task.execute(); ... } public void rendertext() { ... } class loadtexttask extends asynctask<integer, void, boolean> { @override protected void onpreexecute() { // how access fragment or activity here? progressbar loader = (progressbar) findviewbyid(r.id.textloadingprogressbar); loader.setvisibility(textview.visible); } @override protected void onpostexecute(boolean loaded) { // how trigger rendertext method defined on textreaderfragment? loader.setvisibility(textview.gone); }
i don't understand how can:
- access
fragment
oractivity
onpreexecute()
method ui widgets defined infragment
oractivity
- trigger
rendertext()
method defined intextreaderfragment
onpostexecute()
?
answers point-wise:
- the
fragment
can accessedtextreaderfragment.this
. - the
activity
can accessed(myactivity)getactivity()
. rendertext()
can called usingtextreaderfragment.this.rendertext()
.
Comments
Post a Comment