textview - how to put the heading after the header() in android -


hi in below fetching data database , getting json response , displaying in android table layout.but working fine want put sub headings displaying data took textview in using settext() giving sub heading.but it's not displaying proper heading.

this output when running app:

general registration si  date        toatal registration 1   2015-04-01     2 2   2015-04-02     3 1   2015-04-02     3 

expected output:

    si  date        toatal registration general registration     1   2015-04-01     2     2   2015-04-02     3 ipd registration     1   2015-04-02     3 

java

public class datewise_patient_list extends activity {      string data = "",result="";     tablelayout tl;     tablerow tr;    textview si,tv;     string querystring;     int numofpatients = 0;    textview[] snos;     textview[] date;     textview[] tot_reg;       @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.datewise_collection_report);          tl = (tablelayout) findviewbyid(r.id.maintable);         tv=(textview)findviewbyid(r.id.tv);         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("datewise_collection_report",querystring);                 system.out.println(data);                    runonuithread(new runnable() {                      @override                     public void run() {                         arraylist<datewise_patients> datewisepatients = parsejson(data);                         numofpatients = datewisepatients.size();                         adddata(datewisepatients);                                          }                 });              }         }).start();         new thread(new runnable() {             public void run() {                 querystring = "date1=" + date1 + "&date2="                         + date2;                 result = databaseutility.executequeryphp("datewise_ipd_report",querystring);                 system.out.println(result);                   runonuithread(new runnable() {                      @override                     public void run() {                         arraylist<datewise_patients> datewiseipdpatients = parsejson1(result);                         numofpatients = datewiseipdpatients.size();                         adddata1(datewiseipdpatients);                                          }                 });              }         }).start();              }      public arraylist<datewise_patients> parsejson(string data) {         arraylist<datewise_patients> datewisepatients = new arraylist<datewise_patients>();         try {             jsonarray jarray = new jsonarray(data);             (int = 0; < jarray.length(); i++) {                 jsonobject json_data = jarray.getjsonobject(i);                 datewise_patients datewisepatient = new datewise_patients();                  datewisepatient.setdate(json_data.getstring("date"));                 datewisepatient.settot_reg(json_data.getstring("total"));                 datewisepatients.add(datewisepatient);             }         } catch (jsonexception e) {             log.e("log_tag", "error parsing data " + e.tostring());           }         return datewisepatients;     }     public arraylist<datewise_patients> parsejson1(string result) {         arraylist<datewise_patients> datewiseipdpatients = new arraylist<datewise_patients>();         try {             jsonarray jarray = new jsonarray(result);             (int = 0; < jarray.length(); i++) {                 jsonobject json_data = jarray.getjsonobject(i);                 datewise_patients datewiseipdpatient = new datewise_patients();                  datewiseipdpatient.setdate(json_data.getstring("date"));                 datewiseipdpatient.settot_reg(json_data.getstring("total"));                 datewiseipdpatients.add(datewiseipdpatient);             }         } catch (jsonexception e) {             log.e("log_tag", "error parsing data " + e.tostring());           }         return datewiseipdpatients;     }       void addheader(){         /** create tablerow dynamically **/          tr = new tablerow(this);          /** creating textview add row **/          si = new textview(this);         si.settext("si");         si.setlayoutparams(new layoutparams(layoutparams.wrap_content,                layoutparams.wrap_content));         si.setpadding(5, 5, 5, 5);           linearlayout ll = new linearlayout(this);       linearlayout.layoutparams params = new linearlayout.layoutparams(layoutparams.fill_parent,                 layoutparams.wrap_content);         params.setmargins(5, 5, 5, 5);         ll.addview(si,params);         tr.addview((view)ll); // adding textview tablerow.           /** creating qty button **/         textview date = new textview(this);         date.settext("date");         date.settextsize(15);         date.settextcolor(color.parsecolor("#ffa500"));         date.setlayoutparams(new layoutparams(layoutparams.wrap_content,                  layoutparams.wrap_content));         date.setpadding(5, 5, 5, 5);         // pat_name.setbackgroundcolor(color.parsecolor("#075e93"));          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(date,params);          tr.addview((view)ll); // adding textview tablerow.            /** creating qty button **/          textview tot_reg = new textview(this);          tot_reg.settext("total registrations");          tot_reg.setlayoutparams(new layoutparams(layoutparams.wrap_content,                  layoutparams.wrap_content));          tot_reg.setpadding(5, 5, 5, 5);          //reg_date.setbackgroundcolor(color.parsecolor("#075e93"));          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(tot_reg,params);          tr.addview((view)ll); // adding textview tablerow.           tl.addview(tr, new tablelayout.layoutparams(                 layoutparams.fill_parent,                 layoutparams.wrap_content));     }      @suppresswarnings({ "rawtypes", "deprecation" })     public void adddata(arraylist<datewise_patients> datewisepatients) {          snos = new textview[numofpatients];         date = new textview[numofpatients];         tot_reg=new textview[numofpatients];           int j = 0;           addheader();          tv.settext("general registration");           (iterator = datewisepatients.iterator(); i.hasnext();) {               snos[j] = (textview) findviewbyid(r.id.si);             date[j] = (textview) findviewbyid(r.id.date);             tot_reg[j]=(textview)findviewbyid(r.id.tot_reg);                datewise_patients p = (datewise_patients) i.next();              /** create tablerow dynamically **/             tr = new tablerow(this);             if(j % 2==0){                tr.setbackgroundcolor(color.parsecolor("#00bfff"));            }                else{                     tr.setbackgroundcolor(color.parsecolor("#ffffe0"));                }                /** creating textview add row **/            snos[j] = new textview(this);            int temp = j;            snos[j].settext(string.valueof(temp +1));            snos[j].setid(j);            snos[j].setlayoutparams(new layoutparams(layoutparams.wrap_content,                     layoutparams.wrap_content));            snos[j].setpadding(5, 5, 5, 5);           // snos[j].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(snos[j],params);             tr.addview((view)ll); // adding textview tablerow.               /** creating qty button **/             date[j] = new textview(this);             date[j].setkeylistener(null);             date[j].settext(p.getdate());             date[j].setlayoutparams(new layoutparams(layoutparams.wrap_content,                     layoutparams.wrap_content));             date[j].setpadding(5, 5, 5, 5);           //  patnames[j].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(date[j],params);             tr.addview((view)ll); // adding textview tablerow.               /** creating qty button **/             tot_reg[j] = new textview(this);             tot_reg[j].setkeylistener(null);             tot_reg[j].settext(p.gettot_reg());             tot_reg[j].setlayoutparams(new layoutparams(layoutparams.wrap_content,                     layoutparams.wrap_content));             tot_reg[j].setpadding(5, 5, 5, 5);          //   regdates[j].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(tot_reg[j],params);             tr.addview((view)ll); // adding textview tablerow.                // add tablerow tablelayout             tl.addview(tr, new tablelayout.layoutparams(                     layoutparams.fill_parent,                     layoutparams.wrap_content));             j++;         }     }     @suppresswarnings({ "rawtypes", "deprecation" })     public void adddata1(arraylist<datewise_patients> datewiseipdpatients) {          snos = new textview[numofpatients];         date = new textview[numofpatients];         tot_reg=new textview[numofpatients];           int j = 0;      //  tv.settext("ipd patient list");             (iterator = datewiseipdpatients.iterator(); i.hasnext();) {               snos[j] = (textview) findviewbyid(r.id.si);             date[j] = (textview) findviewbyid(r.id.date);             tot_reg[j]=(textview)findviewbyid(r.id.tot_reg);                datewise_patients p = (datewise_patients) i.next();              /** create tablerow dynamically **/             tr = new tablerow(this);             if(j % 2==0){                tr.setbackgroundcolor(color.parsecolor("#00bfff"));            }                else{                     tr.setbackgroundcolor(color.parsecolor("#ffffe0"));                }                /** creating textview add row **/            snos[j] = new textview(this);            int temp = j;            snos[j].settext(string.valueof(temp +1));            snos[j].setid(j);            snos[j].setlayoutparams(new layoutparams(layoutparams.wrap_content,                     layoutparams.wrap_content));            snos[j].setpadding(5, 5, 5, 5);           // snos[j].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(snos[j],params);             tr.addview((view)ll); // adding textview tablerow.               /** creating qty button **/             date[j] = new textview(this);             date[j].setkeylistener(null);             date[j].settext(p.getdate());             date[j].setlayoutparams(new layoutparams(layoutparams.wrap_content,                     layoutparams.wrap_content));             date[j].setpadding(5, 5, 5, 5);           //  patnames[j].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(date[j],params);             tr.addview((view)ll); // adding textview tablerow.               /** creating qty button **/             tot_reg[j] = new textview(this);             tot_reg[j].setkeylistener(null);             tot_reg[j].settext(p.gettot_reg());             tot_reg[j].setlayoutparams(new layoutparams(layoutparams.wrap_content,                     layoutparams.wrap_content));             tot_reg[j].setpadding(5, 5, 5, 5);          //   regdates[j].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(tot_reg[j],params);             tr.addview((view)ll); // adding textview tablerow.                // add tablerow tablelayout             tl.addview(tr, new tablelayout.layoutparams(                     layoutparams.fill_parent,                     layoutparams.wrap_content));             j++;         }     } 


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -