android - using Buttons to retrieve data from database -


i have connected database in android application. have created button , when clicked, should next data table of database. have cursor , movetofirst() , movetonext() methods in code. have set onclick listener button. in output when click button, not fetching next data database

heres part of code have tried set on click listener button

 c=mydbhelper.query(mydbhelper.db_path +"/maintable",null, null, null, null,null, null);         c.movetofirst();                   myques=(textview)findviewbyid(r.id.question);                  myrg=(radiogroup)findviewbyid(r.id.rg1);                  myc1=(radiobutton)findviewbyid(r.id.radio0);                  myc2=(radiobutton)findviewbyid(r.id.radio1);                  myc3=(radiobutton)findviewbyid(r.id.radio2);                  myc4=(radiobutton)findviewbyid(r.id.radio3);                  nxtques=(button)findviewbyid(r.id.button1);                  myques.settext(c.getstring(1));                myc1.settext(c.getstring(2));                myc2.settext(c.getstring(3));                myc3.settext(c.getstring(4));                myc4.settext(c.getstring(5));                nxtques.setonclicklistener(new onclicklistener()             {                 @override                 public void onclick(view v)                 {                      c.movetonext();                 }              }); 

what changes should make in code set on click listener in proper way.

so in code few problems. @ first here:

c = mydbhelper.query(mydbhelper.db_path +"/maintable", ...); 

as first parameter of query() method "raw" tablename can't assign there full path of database(if isn't real tablename...), it's wrong. assign maintable this:

c = mydbhelper.query("maintable", null, null, null, null, null, null); 

then logic fetching data database not @ all. assigned values widgets once , no more. never refreshed, need call many times settext() method want update widget's content. don't update them.

you need change logic to:

@override public void onclick(view v) {   if (c.movetonext()) {      myques.settext(c.getstring(1));      myc1.settext(c.getstring(2));      myc2.settext(c.getstring(3));      myc3.settext(c.getstring(4));      myc4.settext(c.getstring(5));   } } 

recommendation: when using "getters" methods of cursor, recommend use column names columns indexes:

myques.settext(c.getstring(c.getcolumnindex("columnname"))); 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -