android - how do i randomize without repetitions questions in a quiz app? -


between these 2 functions 1 should implement randomize questions database more efficiently.

getquestion # 1

public void getquestion() {      random r = new random();     int n = r.nextint(2);     dbase = this.getreadabledatabase();     ctr++;      //cursor cursor = dbase.rawquery("select * " + table_quest + " `qid` = " + n + ";", null);     cursor cursor = dbase.rawquery("select * "+table_quest+" order random()"+""+ ";", null);      if (cursor.movetofirst()) {         if(cursor.getint(6) == 1) {             ta.txtquestion.setvisibility(view.visible);             ta.txtquestion.settext(cursor.getstring(1).tostring());            /* log.e("image", "i here");             ta.img.setvisibility(view.visible);             int imageresource = draw.getresources().getidentifier("@drawable/"+cursor.getstring(1), null, package);             drawable res = draw.getresources().getdrawable(imageresource);             ta.img.setimagedrawable(res);             //ta.img.setimageresource(imageresource);*/         } else {             ta.txtquestion.setvisibility(view.visible);             ta.txtquestion.settext(cursor.getstring(1).tostring());         }         ta.button1.settext(cursor.getstring(3).tostring());         ta.button2.settext(cursor.getstring(4).tostring());         ta.button3.settext(cursor.getstring(5).tostring());         ta.ans = cursor.getstring(2).tostring();         log.e("current question id", integer.tostring(n));         testactivity.txtcounter.settext(integer.tostring(ctr));     } } 

get question number 2

 public list<question> getallquestions() {     list<question> queslist = new arraylist<question>();     // select query     string selectquery = "select  * " + table_quest;     dbase = this.getreadabledatabase();     cursor cursor = dbase.rawquery(selectquery, null);     // looping through rows , adding list     if (cursor.movetofirst()) {         {            // question quest = new question();             //quest.setid(cursor.getint(0));             question quest = new question();             quest.setid(cursor.getint(0));             quest.setquestion(cursor.getstring(1));             quest.setanswer(cursor.getstring(5));             quest.setopta(cursor.getstring(2));             quest.setoptb(cursor.getstring(3));             quest.setoptc(cursor.getstring(4));              queslist.add(quest);         } while (cursor.movetonext());     }     // return quest list     return queslist; } 

so question is... 1 better use , missing make work?


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -