How to display the data in table view in android eclipse -


public void showdata(view view)     {         cursor c = db.rawquery("select * student2", null);         int count = c.getcount();         c.movetofirst();         tablelayout tablelayout = new tablelayout(getapplicationcontext());         tablelayout.setverticalscrollbarenabled(true);         tablerow tablerow;         textview textview, textview1, textview3, textview5;         tablerow = new tablerow(getapplicationcontext());          textview = new textview(getapplicationcontext());         textview.settext("name");         textview.settextcolor(color.red);         textview.settypeface(null, typeface.bold);         textview.setpadding(20, 20, 20, 20);         tablerow.addview(textview);           textview5 = new textview(getapplicationcontext());         textview5.settext("email");         textview5.settextcolor(color.red);         textview5.settypeface(null, typeface.bold);         textview5.setpadding(20, 20, 20, 20);         tablerow.addview(textview5);         tablelayout.addview(tablerow);          for(integer j=0; j< count; j++)         {             tablerow = new tablerow(getapplicationcontext());              textview1 = new textview(getapplicationcontext());             textview1.settext(c.getstring(c.getcolumnindex(name)));               textview3 = new textview(getapplicationcontext());             textview3.settext(c.getstring(c.getcolumnindex(email)));              textview1.setpadding(20, 20, 20, 20);             textview3.setpadding(20, 20, 20, 20);              tablerow.addview(textview1);             tablerow.addview(textview3);              tablelayout.addview(tablerow);             c.movetonext();         }         setcontentview(tablelayout);         db.close();     } 

i've tested code dummy students, working fine me.

please verify getting students iterating cursor. put log.d("tag","some_student") testing

also, should use youractivityname.this in place of getapplicationcontext(). example

tablerow = new tablerow(this); 

full code using dummy students

import android.app.activity; import android.graphics.color; import android.graphics.typeface; import android.os.bundle; import android.widget.tablelayout; import android.widget.tablerow; import android.widget.textview;  import java.util.arraylist; import java.util.list;  public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          list<student> students = new arraylist<>();         students.add(new student("rahul","rahul@gmail.com"));         students.add(new student("shweta","shweta@gmail.com"));         students.add(new student("test","test@gmail.com"));         students.add(new student("mohan","mohan@gmail.com"));           tablelayout tablelayout = new tablelayout(this);         tablelayout.setverticalscrollbarenabled(true);         tablerow tablerow;         textview textview, textview1, textview3, textview5;         tablerow = new tablerow(this);          textview = new textview(this);         textview.settext("name");         textview.settextcolor(color.red);         textview.settypeface(null, typeface.bold);         textview.setpadding(20, 20, 20, 20);         tablerow.addview(textview);           textview5 = new textview(this);         textview5.settext("email");         textview5.settextcolor(color.red);         textview5.settypeface(null, typeface.bold);         textview5.setpadding(20, 20, 20, 20);         tablerow.addview(textview5);         tablelayout.addview(tablerow);          for(integer j=0; j< students.size(); j++)         {             tablerow = new tablerow(this);              textview1 = new textview(this);             textview1.settext(students.get(j).getname());               textview3 = new textview(this);             textview3.settext(students.get(j).getemail());              textview1.setpadding(20, 20, 20, 20);             textview3.setpadding(20, 20, 20, 20);              tablerow.addview(textview1);             tablerow.addview(textview3);              tablelayout.addview(tablerow);         }         setcontentview(tablelayout);      }      class student {         string name;         string email;          public student(string name, string email) {             this.name = name;             this.email = email;         }          public string getname() {             return name;         }          public void setname(string name) {             this.name = name;         }          public string getemail() {             return email;         }          public void setemail(string email) {             this.email = email;         }     } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -