android - Change TextView in Fragment OnPreExecute -


i trying change text view in onpreexecute method in asynctask, keep getting null point exception. or alternatives appreciated.

public class fragmentone extends sherlockfragment {

@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {      new longoperation().execute("");      view view = inflater.inflate(r.layout.fragmentone, container, false);     return view;  }   private class longoperation extends asynctask<string, void, string> {      @override     protected void onpreexecute() {         textview txt = (textview) getview().findviewbyid(r.id.textview1);         txt.settext("\nloading...");     }      // etc etc etc } 

}

i think code work after doing following change. :d null pointer come getview() think

    textview txt = null;     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate)     {          view view = inflater.inflate(r.layout.fragmentone, container, false);         txt = (textview) view.findviewbyid(r.id.textview1);         new longoperation().execute("");         return view;      }     private class longoperation extends asynctask<string, void, string> {          @override         protected void onpreexecute() {             txt.settext("\nloading...");         }          // etc etc etc     } 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -