Friday 15 June 2012

java - Is there an easy way to populate a ListView with Cursor? -



java - Is there an easy way to populate a ListView with Cursor? -

i wondering if there easy way fill listview cursor, can edittext:

final edittext visnavn=(edittext)findviewbyid(r.id.visnavn); dbadapter db; cursor cur = db.findall(); if(cur.movetofirst()){ do{ visnavn.append(cur.getstring(0)); visnavn.append(" "); visnavn.append(cur.getstring(1)); visnavn.append("\n"); }while(cur.movetonext()); } cur.close();

i've tried this, no luck:

cursor c = db.findall(); listview list = (listview)findviewbyid(r.id.list); if(c.movetofirst()){ do{ list.add(c.getstring(0)); list.add(" "); list.add(c.getstring(1)); }while(c.movetonext()); } c.close();

oke, said in comments there easy way load cursor info listview, here code used. maybe it's useful you! :)

final cursor locations = <get info here> locations.movetofirst(); layoutinflater inflater = this.getlayoutinflater(); while ( locations.isafterlast() == false ) { view tablerow = inflater.inflate(r.layout.tablerow, null); textview txtname = (textview)tablerow.findviewbyid(r.id.txtname); txtname.settext(locations.getstring(1)); sview.addview(tablerow); locations.movetonext(); }

java android android-listview android-sqlite android-cursor

No comments:

Post a Comment