Methods of Fragment class in android not getting called -


hi beginner android , in app have show slidingpanelayout @ right side

ok ok

but when tapped on slidingpanelayout 1 of row want o reload listview wrote below code

but here listview reloading default ,but when tapped on slidingpanelayout it's not reloading

below lines not executing when calling getalltips() method mainactivity

if (friendarraylist.size() != 0) {
                 log.d("=======>" ," data available");
        ˚         adapter.notifydatasetchanged();
             }else{
              log.d("=======>" ,"no data available");
             } 

listviewfragment:-

public class listviewfragment extends fragment implements asynctaskclass.backgroundservicecall {      private arraylist<mytripbean> friendarraylist;     listviewadapter adapter;      @nullable     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {          view view =inflater.inflate(r.layout.listview_layout,container,false);          listview listview = (listview)view.findviewbyid(r.id.list_item);          //set listview header:-         inflater =  getactivity().getlayoutinflater();         view header = inflater.inflate(r.layout.header_listview,listview,false);         listview.addheaderview(header);          //adapter = new listviewadapter(getactivity(), r.layout.item_listview, friendarraylist);          friendarraylist =  new arraylist<mytripbean>();          adapter = new listviewadapter(getactivity(),                 r.layout.list_item, friendarraylist);          listview.setadapter(adapter);          getalltips(getactivity(),9); //getting friendarraylist data services          return view;     }      // trips of user     public void getalltips(activity activity,int tripstatus) {          try {              jsonobject json = new jsonobject();             json.put("tripstatus", tripstatus);             json.put("medicaidid", "104584743999");              if (commonutilities.isnetworkstateavailble(activity)) {                  asynctaskclass task = new asynctaskclass(this, activity,                         json);                 task.execute(serviceurl.get_all_trips, "1",                         "token");              } else {                 log.d("==========>", "there network error");             }          } catch (jsonexception e) {             // todo auto-generated catch block             e.printstacktrace();         }     }      @override     public void dopostexecute(statusobject statusobject) {          // todo auto-generated method stub         if (statusobject != null) {              if (statusobject.getresponsecode() == 401) {                 log.d("==========>", "session has been expired");              } else if (statusobject.getresponsecode() == 200) {                  handleresponsedata(statusobject.getmessage());              } else {                 log.d("==========>", "server not responding. please try again later.");             }          } else {             log.d("==========>", "server not responding. please try again later.");         }     }      // handle response     public void handleresponsedata(string result) {          log.d("final json==========>", result);          try {             object json = new jsontokener(result).nextvalue();             if (json instanceof jsonobject) {                 // have object                  jsonobject jsonobject = new jsonobject(result);                 if (jsonobject.has("error")) {                      if (jsonobject.getstring("error").equalsignorecase("true")) {                          if (jsonobject.has("message")) {                              log.d("==========>", "there erorr mesage coming server");                         }                     }                 }             } else if (json instanceof jsonarray) {                 // have array                 handletripsresponse(result);             }          } catch (jsonexception e) {             // todo auto-generated catch block             e.printstacktrace();         }     }      // handle json array data     public void handletripsresponse(string result) {          try {              type type = new typetoken<list<mytripbean>>() {             }.gettype();              arraylist<mytripbean>  newlistdata = new gson().fromjson(result, type);             friendarraylist.addall(newlistdata);              if (friendarraylist.size() != 0) {                 log.d("=======>" ," data available");                 adapter.notifydatasetchanged();             }else{                 log.d("=======>" ,"no data available");             }          } catch (throwable throwable) {          }     } } 

mainactivity:-

public class mainactivity extends appcompatactivity {      slidingpanelayout mslidingpanel;     listview mmenulist;      string [] menutitles = new string[]{"first item","second item","third item","fourth item"};      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main_layout);          mmenulist.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                  listviewfragment fragment1 = new listviewfragment();                 fragment1.getalltips(mainactivity.this,8);             }         });     } 

the code looks fine. onitemclicklisteners looks fine listview , work correctly. doubt if getting exception in method handletripsresponse(). please try printing log in catch block of method. come know exception , how resolve it.

also in mainactivity, in onitemclicklistener, not create new instance of listviewfragment, instead use instance of fragment attached in fragment transaction.

 listviewfragment fragment1 = new listviewfragment();             fragment1.getalltips(mainactivity.this,8); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -