how arraylist
jsonobject
request?
i tried interface doesn't work. setter , getter doesn't work too. using recyclerview
.
this code,
public class editdoctor extends fragment { recyclerview recyclerview; string key; string url; recycleradaptereditdoctor edit; sharedpreferences sharedpreferences; requestqueue queue; arraylist<editdoctormodel> listofpojo = new arraylist<>(); public editdoctor() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstanestate) { view view = inflater.inflate(r.layout.editdoctor,container,false); context context = getactivity(); sharedpreferences sharedpreferences = preferencemanager.getdefaultsharedpreferences(context); key = sharedpreferences.getstring("key", ""); return view; } @override public void onviewcreated(view view,bundle savedinstancestate) { setretaininstance(true); } @override public void onactivitycreated(@nullable bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); recyclerview = (recyclerview) getactivity().findviewbyid(r.id.recycler1); linearlayoutmanager linearlayoutmanager = new linearlayoutmanager(getactivity()); linearlayoutmanager.setorientation(linearlayoutmanager.vertical); recyclerview.setlayoutmanager(linearlayoutmanager); queue = volley.newrequestqueue(getactivity()); sharedpreferences = preferencemanager.getdefaultsharedpreferences(getactivity()); key = sharedpreferences.getstring("key", ""); url = "http://192.168.0.153:9091/drrate/api/profile/search?page=1&size=10&filter=[{\"col\":\"memberkey\",\"val\":\""+key+"\",\"cond\":\"equal\"}]"; getjsonrequest(); edit = new recycleradaptereditdoctor(getactivity(),listofpojo); recyclerview.setadapter(edit); } // request public void getjsonrequest() { jsonobjectrequest req = new jsonobjectrequest(request.method.get, url, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { arraylist<editdoctormodel>temp = new arraylist<>(); try { jsonarray jarray = response.getjsonarray("data"); (int = 0; < jarray.length(); i++) { jsonobject object = jarray.getjsonobject(i); editdoctormodel editdoctormodel = new editdoctormodel(); editdoctormodel.setfullname(object.getstring("name")); editdoctormodel.setprofession(object.getstring("profession")); editdoctormodel.seturl(object.getstring("image")); temp.add(editdoctormodel); } // work android monitor says skipping layout adapter not attached // edit = new recycleradaptereditdoctor(getactivity(),listofpojo); // recyclerview.setadapter(edit); } catch (jsonexception e) { e.printstacktrace(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { } }); queue.add(req); }
please me. in advance.
add data have parsed dataset listofpojo
, , call notifydatasetchanged
on adapter.
try this,
@override public void onresponse(jsonobject response) { arraylist<editdoctormodel> temp = new arraylist<>(); try { jsonarray jarray = response.getjsonarray("data"); (int = 0; < jarray.length(); i++) { jsonobject object = jarray.getjsonobject(i); editdoctormodel editdoctormodel = new editdoctormodel(); editdoctormodel.setfullname(object.getstring("name")); editdoctormodel.setprofession(object.getstring("profession")); editdoctormodel.seturl(object.getstring("image")); temp.add(editdoctormodel); } // add data in temp listofpojo listofpojo.clear(); listofpojo.addall(temp); // notify adapter data has changed edit.notifydatasetchanged(); } catch (jsonexception e) { e.printstacktrace(); } }
Comments
Post a Comment