How to get data from database in my android table view as columns -


i have done following coding deriving data's table , displayed in android view table columns , rows.

the database coding is

public list<country> getallcountry() {     list<country> countrylist = new arraylist<country>();      //select query     string selectquery = "select * country_list";      sqlitedatabase db = this.getwritabledatabase();     cursor cursor = db.rawquery(selectquery, null);       (cursor.movetofirst(); !cursor.isafterlast(); cursor.movetonext())     {          country country = new country();             country.setid(cursor.getstring(0));             country.setname(cursor.getstring(1));             country.setnationalty(cursor.getstring(2));             country.setdate(cursor.getstring(3));               // adding person list             countrylist.add(country);     }      return countrylist;  } 

the xml is

<tablelayout      android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:id="@+id/tab">   <tablerow       >           </tablerow>     </tablelayout> 

the activity coding is

list<country> country = db.getallcountry();      stringbuilder builder = new stringbuilder();     (country c: country)     {                        builder.append(c.getid()).append(";")             .append(c.getname()).append(";")             .append(c.getnationalty()).append(";")             .append(c.getdate()).append("_");     }     //tv.settext(builder.tostring());      builder.tostring();      string st = new string(builder);     log.d("main",st);     string[] rows  = st.split("_");     tablelayout tablelayout = (tablelayout)findviewbyid(r.id.tab);     tablelayout.removeallviews();      for(int i=0;i<rows.length;i++){         log.d("rows",rows[i]);         string row  = rows[i];         tablerow tablerow = new tablerow(getapplicationcontext());         tablerow.setlayoutparams(new tablelayout.layoutparams(layoutparams.match_parent, layoutparams.wrap_content));         final string[] cols = row.split(";");          handler handler = null;          (int j = 0; j < cols.length; j++) {                          final string col = cols[j];                                              textview columsview = new textview(getapplicationcontext());             columsview.setlayoutparams(new tablerow.layoutparams(tablerow.layoutparams.wrap_content, tablerow.layoutparams.wrap_content));             columsview.settextcolor(color.black);             columsview.settext(string.format("%7s", col));                                             log.d("cols", string.format("%7s", col));             tablerow.addview(columsview);          }     } 

the above code not printing in android emulator screen.

please have done wrong.

thanks in advance.

regards, dinesh

i guess missing tablelayout.addview(tablerow) on last line of 1st loop after coming out of 2nd loop..else row not added..


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -