android- How to search json data using retrofit and show the results? -
i made list view , showing json data on online. want add search functionality , show filter results.
this screenshot enter image description here
when type listview disappears , doesn't show results.
this code
mainactivityrecyc
public class mainactivityrecyc extends appcompatactivity { public listview listview; private view parentview; public arraylist<locations> locationslist; public dataadapter adapter; // search edittext edittext inputsearch; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main_recyc); locationslist= new arraylist<>(); parentview=findviewbyid(r.id.parentlayout); inputsearch = (edittext) findviewbyid(r.id.inputsearch); listview = (listview) findviewbyid(r.id.listview); inputsearch.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence cs, int arg1, int arg2, int arg3) { // when user changed text mainactivityrecyc.this.adapter.getfilter().filter(cs); } @override public void beforetextchanged(charsequence arg0, int arg1, int arg2, int arg3) { // todo auto-generated method stub } @override public void aftertextchanged(editable arg0) { // todo auto-generated method stub } }); requestinterface api = jsonclient.getapiservice(); /** * calling json */ call<stoplist> call = api.getjson(); /** * enqueue callback call when response... */ call.enqueue(new callback<stoplist>() { @override public void onresponse(call<stoplist> call, response<stoplist> response) { //dismiss dialog // dialog.dismiss(); if(response.issuccessful()) { /** * got */ locationslist = response.body().getlocations(); /** * binding list adapter */ adapter = new dataadapter(mainactivityrecyc.this, locationslist); listview.setadapter(adapter); } else { toast.maketext(getapplicationcontext(), "wrong", toast.length_short).show(); } } @override public void onfailure(call<stoplist> call, throwable t) { toast.maketext(getapplicationcontext(), "wrong", toast.length_short).show(); } }); }
requestinterface public interface requestinterface {
//@headers("content-type:application/json; charset=utf-8") @get("/bins/19frwr.json") call<stoplist> getjson(); }
Comments
Post a Comment