android - How to retrieve data from SQLite and display in TextView only one at a time when clicked on button -
i have stored data in sqlite. need retrieve data sqlite , should display on text view when click on button. , when again click on button should other text view , should show in text view.
using code can display text view. when click on button displaying every thing sqlite, need 1 text view @ time.
public void display(view v) { //use cursor keep data //cursor can keep data of data type cursor c=db.rawquery("select * mytable", null); tv.settext(""); if(c!=null && c.getcount()>0) { //move cursor first position c.movetofirst(); //fetch data 1 one { //we can use c.getstring(0) here //or can data using column index string name=c.getstring(c.getcolumnindex("name")); string surname=c.getstring(1); //display on text view tv.append(name+surname+"\n"); //move next position until end of data }while(c.movetonext()); } }
modify code below
cursor c = null; public void display(view v) { //use cursor keep data //cursor can keep data of data type if(c == null) { c=db.rawquery("select * mytable", null); //move cursor first position c.movetofirst(); } tv.settext(""); if(c!=null && c.getcount()>0 && !c.isafterlast()) { //we can use c.getstring(0) here //or can data using column index string name=c.getstring(c.getcolumnindex("name")); string surname=c.getstring(1); //display on text view tv.settext(name+surname+"\n"); c.movetonext(); } }
Comments
Post a Comment