json data not displaying in table layout in android -
hi in below code displaying table layout table format.but in activity displaying heading.but values not displaying.
in below code data string displaying values
can 1 me
java
public class general_patient_list extends activity { string data = ""; tablelayout tl; tablerow tr; textview label; string querystring; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.general_collection_report); tl = (tablelayout) findviewbyid(r.id.maintable); final string date1 = getintent().getstringextra("date1"); final string date2 = getintent().getstringextra("date2"); new thread(new runnable() { public void run() { querystring = "date1=" + date1 + "&date2=" + date2; data = databaseutility.executequeryphp("general_registration",querystring); system.out.println(data); runonuithread(new runnable() { @override public void run() { arraylist<patients> patients = parsejson(data); adddata(patients); } }); } }).start(); } public arraylist<patients> parsejson(string result) { arraylist<patients> patients = new arraylist<patients>(); try { jsonarray jarray = new jsonarray(result); (int = 0; < jarray.length(); i++) { jsonobject json_data = jarray.getjsonobject(i); patients patient = new patients(); //patient.setsi(json_data.getint("si")); patient.setregno(json_data.getstring("reg_no")); // patient.setpat_name(json_data.getstring("pat_name")); patient.setsex(json_data.getstring("sex")); patient.setreg_date(json_data.getstring("reg_date")); patient.setaddress(json_data.getstring("address")); patients.add(patient); } } catch (jsonexception e) { log.e("log_tag", "error parsing data " + e.tostring()); } return patients; } void addheader(){ /** create tablerow dynamically **/ tr = new tablerow(this); /** creating textview add row **/ // label = new textview(this); //label.settext("si"); // label.setlayoutparams(new layoutparams(layoutparams.wrap_content, // layoutparams.wrap_content)); //label.setpadding(5, 5, 5, 5); //label.setbackgroundcolor(color.red); // linearlayout ll = new linearlayout(this); // linearlayout.layoutparams params = new linearlayout.layoutparams(layoutparams.fill_parent, // layoutparams.wrap_content); // params.setmargins(5, 5, 5, 5); //ll.setpadding(10, 5, 5, 5); // ll.addview(label,params); // tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview reg_no = new textview(this); reg_no.settext("reg_no"); reg_no.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); reg_no.setpadding(5, 5, 5, 5); reg_no.setbackgroundcolor(color.red); linearlayout ll = new linearlayout(this); ll = new linearlayout(this); linearlayout.layoutparams params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 5, 5, 5); //ll.setpadding(10, 5, 5, 5); ll.addview(reg_no,params); tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview pat_name = new textview(this); pat_name.settext("patient name"); pat_name.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); pat_name.setpadding(5, 5, 5, 5); pat_name.setbackgroundcolor(color.red); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 5, 5, 5); //ll.setpadding(10, 5, 5, 5); ll.addview(pat_name,params); tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview sex = new textview(this); sex.settext("sex"); sex.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); sex.setpadding(5, 5, 5, 5); sex.setbackgroundcolor(color.red); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 5, 5, 5); //ll.setpadding(10, 5, 5, 5); ll.addview(sex,params); tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview reg_date = new textview(this); reg_date.settext("registration date"); reg_date.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); reg_date.setpadding(5, 5, 5, 5); reg_date.setbackgroundcolor(color.red); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 5, 5, 5); //ll.setpadding(10, 5, 5, 5); ll.addview(reg_date,params); tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview address = new textview(this); address.settext("address"); address.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); address.setpadding(5, 5, 5, 5); address.setbackgroundcolor(color.red); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 5, 5, 5); //ll.setpadding(10, 5, 5, 5); ll.addview(address,params); tr.addview((view)ll); // adding textview tablerow. // add tablerow tablelayout tl.addview(tr, new tablelayout.layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); } @suppresswarnings({ "rawtypes", "deprecation" }) public void adddata(arraylist<patients> patients) { addheader(); (iterator = patients.iterator(); i.hasnext();) { patients p = (patients) i.next(); /** create tablerow dynamically **/ tr = new tablerow(this); /** creating textview add row **/ //label = new textview(this); // label.settext(p.getsi()); // label.setid(p.getsi()); // label.setlayoutparams(new layoutparams(layoutparams.wrap_content, // layoutparams.wrap_content)); // label.setpadding(5, 5, 5, 5); // label.setbackgroundcolor(color.gray); // linearlayout ll = new linearlayout(this); // linearlayout.layoutparams params = new linearlayout.layoutparams(layoutparams.fill_parent, // layoutparams.wrap_content); // params.setmargins(5, 2, 2, 2); //ll.setpadding(10, 5, 5, 5); // ll.addview(label,params); // tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview reg_no = new textview(this); reg_no.settext(p.getregno()); reg_no.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); reg_no.setpadding(5, 5, 5, 5); reg_no.setbackgroundcolor(color.gray); linearlayout ll = new linearlayout(this); linearlayout.layoutparams params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 2, 2, 2); //ll.setpadding(10, 5, 5, 5); ll.addview(reg_no,params); tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview pat_name = new textview(this); pat_name.settext(p.getpat_name()); pat_name.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); pat_name.setpadding(5, 5, 5, 5); pat_name.setbackgroundcolor(color.gray); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 2, 2, 2); //ll.setpadding(10, 5, 5, 5); ll.addview(pat_name,params); tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview sex = new textview(this); sex.settext(p.getsex()); sex.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); sex.setpadding(5, 5, 5, 5); sex.setbackgroundcolor(color.gray); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 2, 2, 2); //ll.setpadding(10, 5, 5, 5); ll.addview(sex,params); tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview reg_date = new textview(this); reg_date.settext(p.getreg_date()); reg_date.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); reg_date.setpadding(5, 5, 5, 5); reg_date.setbackgroundcolor(color.gray); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 2, 2, 2); //ll.setpadding(10, 5, 5, 5); ll.addview(reg_date,params); tr.addview((view)ll); // adding textview tablerow. /** creating qty button **/ textview address = new textview(this); address.settext(p.getaddress()); address.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); address.setpadding(5, 5, 5, 5); address.setbackgroundcolor(color.gray); ll = new linearlayout(this); params = new linearlayout.layoutparams(layoutparams.fill_parent, layoutparams.wrap_content); params.setmargins(0, 2, 2, 2); //ll.setpadding(10, 5, 5, 5); ll.addview(address,params); tr.addview((view)ll); // adding textview tablerow. // add tablerow tablelayout tl.addview(tr, new tablelayout.layoutparams( layoutparams.fill_parent, layoutparams.wrap_content)); } }
try replacing loop below
for (int i=0; i<patients.size(); i++) { patients p = patients.get(i); }
also check if patients array empty or not debugging.
Comments
Post a Comment