android - Json Volley Fragments from TabHost -


i'm downloading data server , want set listview. doesn't work. below it's method provides data server.

 @override public void getvillages(string name, final taskdonelistener<village> listener) {     string url = apiservice.url_base + "villages/search?s=" + name;     final jsonparser jparser = new jsonparser();       jsonobjectrequest req = new jsonobjectrequest(url, null, new response.listener<jsonobject>() {         @override         public void onresponse(jsonobject response) {             try {                 village village = new village(                         response.getlong("id"),                         response.getstring("name"),                         response.getstring("logo"),                         response.getboolean("isactive"),                         response.getstring("contact_person"),                         response.getstring("contact_email"),                         response.getstring("contact_person"),                         response.getstring("contact_phone"),                         response.getstring("contact_form_email"),                         response.getstring("latitude"),                         response.getstring("longitude"),                         response.getstring("region"),                         outputformatter.parsedatetime(response.getstring("valid_from")),                         outputformatter.parsedatetime(response.getstring("valid_to")));                 list<village> list = new arraylist<>();                 list.add(village);                 log.i("api", "delka " + list.size());                 listener.ontaskdone(list);             } catch (jsonexception e) {                 e.printstacktrace();             }         }     }, new response.errorlistener() {         @override         public void onerrorresponse(volleyerror error) {             networkresponse networkresponse = error.networkresponse;              if (networkresponse != null) {                 int code = error.networkresponse.statuscode;                 log.i("getvillages", "error response code: " + code);             }         }     });       apiservice.addtorequestqueue(req, "list_villages"); 

my custom adapter

public class searchadapter extends arrayadapter<village> { private context mcontext; private viewholder viewholder; private int resource;  public searchadapter(context context, int resource) {     super(context, resource);     mcontext = context;     this.resource = resource;  }  @override public view getview(int position, view convertview, viewgroup parent) {     final view view = getworkingview(convertview);     viewholder = getviewholder(view);     final village entry = getitem(position);     log.i("villageapiservice", entry.getname());     viewholder.name.settext(entry.getname());      return view; }  private view getworkingview(final view convertview) {     view workingview = null;      if (null == convertview) {         final context context = getcontext();         final layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);          workingview = inflater.inflate(resource, null);     } else {         workingview = convertview;     }      return workingview; }  private viewholder getviewholder(final view workingview) {     final object tag = workingview.gettag();     viewholder viewholder = null;      if (null == tag || !(tag instanceof viewholder)) {         viewholder = new viewholder();         viewholder.name = (textview) workingview.findviewbyid(r.id.event_title);         workingview.settag(viewholder);      } else {         viewholder = (viewholder) tag;     }      return viewholder; }  public void addall(list<village> villagelist) {     super.addall(villagelist); }  private viewholder getviewholder(final view view) {     final object tag = view.gettag();     viewholder viewholder = null;      if (null == tag || !(tag instanceof viewholder)) {         viewholder = new viewholder();          viewholder.name = (textview) view.findviewbyid(r.id.name);         view.settag(viewholder);      } else {         viewholder = (viewholder) tag;     }      return viewholder; }  public void addall(list<village> villagelist) {     super.addall(villagelist); }    static class viewholder {     textview name; } 

}

this fragment started tabhost , here call getvillages.

public class newvillagesearchfragment extends fragment {  private ivillageapiservice villageapiservice; searchadapter madapter; textview tv;  public newvillagesearchfragment() { }  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     villageapiservice = bootstrapper.getvillageapiservice();   }  @override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     view v = inflater.inflate(r.layout.fragment_new_village_search, container, false);      return v;  }   @override public void onactivitycreated(bundle savedinstancestate) {     super.onactivitycreated(savedinstancestate);     final listview listview = (listview) getview().findviewbyid(r.id.listview);     final searchadapter adapter = new searchadapter(getactivity(), r.layout.item_new_village);     log.i("api", "onactivitycreated ");      if(!(villageapiservice == null)) log.i("api", "villageapiservice neni null ");     string name = "adamov";      villageapiservice.getvillages(name, new taskdonelistener<village>() {         @override         public void ontaskdone(list<village> list) {             if(list.isempty()) log.i("newsearchfragment", "je prazdny");             log.i("newsearchfragment", "after ||list: " + list.size());             adapter.addall(list);              listview.setadapter(adapter);             adapter.notifydatasetchanged();           }     });  } 

thank much

i think 're wrong how use listener

you have implements taskdonelistener in newvillagesearchfragment.

exampe code below.

public class newvillagesearchfragment extends fragment implements taskdonelistener {      ....(omit code)      @override     public void ontaskdone(list<village> list) {         if(list.isempty()) log.i("newsearchfragment", "je prazdny");         log.i("newsearchfragment", "after ||list: " + list.size());         adapter.addall(list);          listview.setadapter(adapter);         adapter.notifydatasetchanged();      }      @override     public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);          ...(omit code)          villageapiservice.getvillages(name, this);      } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -