android - update textviews on different fragments based on asyntask result -


i've activity on create calls async task.

public class sync extends baseactivity implements onclicklistener{      @override     public void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_sync);         checkfordevicetask(sync.this).execute(constants.device_address);     } } 

now result of async task determines fragment load inside activity able do. not figure how update textviews inside fragments. please take @ onpostexecute() method. after loading fragment how update textviews based on result?

public class checkfordevicetask extends asynctask<string, integer, string> {     private static final string tag = "checkfordevicetask";     public static final int connected_device_exists = 1;     public static final int waiting_temp_password = 2;     private activity activity;      // private dialogfragment dialogfragment;      public checkfordevicetask(activity activity) {         super();         this.activity = activity;     }      @override     protected void onpreexecute() {         super.onpreexecute();         // fragmentmanager fm = activity.getfragmentmanager();         // dialogfragment = progressdialogfragment.newinstance("saving");         // dialogfragment.show(fm, "dialog");     }      @override     protected string doinbackground(string... params) {         if (gchutils.isconnected(activity)) {             return gchutils.httpget(restapipaths.check_for_device                     + params[0].tostring());         }         return null;     }      @override     protected void onpostexecute(string result) {         // dialogfragment.dismiss();         try {             if (result != null && !result.isempty()) {                 map<string, object> resultmap = maputility.jsontomap(result);                 if (resultmap != null && !resultmap.isempty()) {                     log.d(tag, resultmap.get("status").tostring());                     fragmentmanager fm;                     fragmenttransaction ft;                     if (boolean.valueof(resultmap.get("status").tostring())) {                         int type = integer.valueof(resultmap.get("type")                                 .tostring());                         switch (type) {                         case connected_device_exists: {                             gchconnectedfragment connectedgchfragment = new gchconnectedfragment();                             fm = activity.getfragmentmanager();                             ft = fm.begintransaction();                             ft.replace(r.id.layouttoreplace,                                     connectedgchfragment);                             ft.commit();                             string email = resultmap.get("emailid").tostring();                             string name = resultmap.get("name").tostring();                             // need update 2 textviews in gchconnectedfragment based these values                           }                             break;                         case waiting_temp_password: {                              temppasswordfragment temppasswordfragment = new temppasswordfragment();                             fm = activity.getfragmentmanager();                             ft = fm.begintransaction();                             ft.replace(r.id.layouttoreplace,                                     temppasswordfragment);                             ft.commit();                             string temppassword = resultmap.get("temppassword")                                     .tostring(); // todo: encrypt                             string expirydate = resultmap.get("expirydate")                                     .tostring(); //                          need update 2 textviews in temppasswordfragment based these values                         }                             break;                         }                     } else {                         // todo: init ui connect gch option                         connectgchfragment connectgchfragment = new connectgchfragment();                         fm = activity.getfragmentmanager();                         ft = fm.begintransaction();                         ft.replace(r.id.layouttoreplace, connectgchfragment);                         ft.commit();                     }                 }             }          } catch (exception e) {             log.d(tag, e.getmessage());         }     } } 

first put data eg email , name, in bundle , send bundle arguments destination fragment,as shown below:-

          `bundle bundle = new bundle();             bundle.putserializable("email ", email );             bundle.putboolean("name", name);             fragment.setarguments(bundle);`  

in destination fragment data follows:

                  `string email=getarguments().getstring("email");                    string name=getarguments().getstring("name");` 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -