java - Listview With Asynctask get no response from server -
i want send cus_id postparamname web server. according cus_id want fetch data server , listview.
i have no error in code...but code still not able fetch data server..
plz @ code...i have been working on code since last 2 days. not able find mistake
point1.java
public class points1 extends listactivity implements fetchdatalistener { sessionmanager session; textview tvcuspoints1, tvcuspoints2, tvcusname; textview bus_name; textview cus_points; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.points); initview(); } private void initview() { session = new sessionmanager(getapplicationcontext()); // user data session hashmap<string, string> user = session.getuserdetails(); // id string cus_id = user.get(sessionmanager.key_id); arraylist<namevaluepair> postparamname = new arraylist<namevaluepair>(); postparamname.add(new basicnamevaluepair("cus_id", cus_id)); string url = "http://10.0.2.2/android_api_main/business_points.php"; fetchdatatask task = new fetchdatatask(this); task.execute(url); } @override public void onfetchcomplete(list<application> data) { // dismiss progress dialog // create new adapter applicationadapter adapter = new applicationadapter(this, data); // set adapter list setlistadapter(adapter); } @override public void onfetchfailure(string msg) { // dismiss progress dialog } }
application.java
public class application { private string bus_name; private string cus_points; public string getbus_name() { return bus_name; } public void setbus_name(string bus_name) { this.bus_name = bus_name; } public string getcus_points() { return cus_points; } public void setcus_points(string cus_points) { this.cus_points = cus_points; } }
applicationadapter.java
public class applicationadapter extends arrayadapter<application> { private list<application> items; public applicationadapter(context context, list<application> items) { super(context, r.layout.point_list_item, items); this.items = items; } @override public int getcount() { return items.size(); } @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { layoutinflater li = layoutinflater.from(getcontext()); v = li.inflate(r.layout.point_list_item, null); } application app = items.get(position); if (app != null) { textview titletext = (textview) v.findviewbyid(r.id.item_bname1); textview dltext = (textview) v.findviewbyid(r.id.item_bpoint1); if (titletext != null) titletext.settext(app.getbus_name()); if (dltext != null) dltext.settext(app.getcus_points()); } return v; } }
fetchdatatask.java
public class fetchdatatask extends asynctask<string, void, string> { private final fetchdatalistener listener; private string msg; string cus_id, responsestring, success, bus_name, cus_points; sessionmanager session; public fetchdatatask(fetchdatalistener listener) { this.listener = listener; } @override protected string doinbackground(string... params) { if (params == null) return null; // url params string url = params[0]; try { // create http connection httpclient client = new defaulthttpclient(); httpget httpget = new httpget(url); // connect httpresponse response = client.execute(httpget); // response httpentity entity = response.getentity(); responsestring = entityutils.tostring(entity); // response content , convert json string } catch (ioexception e) { msg = "no network connection"; } return responsestring; } @override protected void onpostexecute(string sjson) { try { jsonobject json = new jsonobject(responsestring); jsonarray jarray = json.getjsonarray("customer"); list<application> apps = new arraylist<application>(); (int = 0; < jarray.length(); i++) { jsonobject json_data = jarray.getjsonobject(i); bus_name = json_data.getstring("bus_name"); cus_points = json_data.getstring("cus_points"); success = json_data.getstring("success"); application app = new application(); app.setbus_name(json.getstring("bus_name")); app.setcus_points(json.getstring("cus_points")); // add app apps apps.add(app); } if (listener != null) listener.onfetchcomplete(apps); } catch (jsonexception e) { msg = "invalid response"; if (listener != null) listener.onfetchfailure(msg); return; } } }
fetchdatalistener.java
public interface fetchdatalistener { public void onfetchcomplete(list<application> data); public void onfetchfailure(string msg); }
your fetchdatatask constructor accepts fetchdatatasklistener parameter
public fetchdatatask(fetchdatalistener listener) { this.listener = listener; }
but have initialized using activity's context
fetchdatatask task = new fetchdatatask(this);
could please check this.
you should set listener correctly, this
this.mlistener = (fetchdatalistener) activity
Comments
Post a Comment