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:

  1. access fragment or activity onpreexecute() method ui widgets defined in fragment or activity
  2. trigger rendertext() method defined in textreaderfragment onpostexecute()?

answers point-wise:

  • the fragment can accessed textreaderfragment.this.
  • the activity can accessed (myactivity)getactivity().
  • rendertext() can called using textreaderfragment.this.rendertext().

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -