I am developing a quiz based app. The quiz contains 1 question and 4 multiple choice answers.
When the user selects any one of the option out of 4, if its a right answer then something like “Your answers is right” should be displayed, else “Your answer is wrong” should be displayed along with the correct answer.
And also there are 2 buttons (next and back), one to go for next question, the other to go back.
Can someone tell me how to write the code for going back to previous question?
I have done something like this:
private void getShuffledArray()
{
// TODO Auto-generated method stub
for (int i = 1; i <= SIZE; i++)
{
quizIndexList.add(i);
}
Collections.shuffle(quizIndexList);
Log.d("ERR", "List A shuffling" + quizIndexList);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right")) {
displayAnswer();
}
break;
case R.id.button2:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right")) {
displayAnswer();
}
break;
case R.id.button3:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right")) {
displayAnswer();
}
break;
case R.id.button4:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right")) {
displayAnswer();
}
break;
case R.id.btn_next:
// lyt_ans.setVisibility(View.GONE);
// lyt_quest.setVisibility(View.VISIBLE);
counter += 1;
if (counter >= SIZE) {
Collections.shuffle(quizIndexList);
counter = 0;
}
getInfoFromDB(quizIndexList.get(counter));
reLoad();
break;
case R.id.btn_bck:
btn_next.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
finish();
}
});
}
}
Any help is appreciable and thank you in advance.
@Rithesh — Not getting your code but simple logic for this as follows
What you need
1) Question array
2) Answers Arraylist (Or say two dimensional array) something like
ArrayList<ArrayList<String>>3) Answer index for each question (It should match to question index
4) A view with a textview (To show question), RadioGroup which consist 4 Radio Buttons so that it will only select one at a time
5) Two buttons next & previous
6) Main thing Add
setOnCheckedChangeListenerto your radio group it will get fire only when user select any answer then check which radio button is checked (For this set tag of radio button to it’s position) so suppose question no is 2 & radio checked position is 3 then just check in your answer array for answer no & if it matches you can show toast & if it’s not match then find write answer from Answers arraylist & show it in toast or by alert.7) now when you click on next button change text view’s text to next question & radio button’s text to next set of answer & vice versa for previous button click
This is logical cant provide you code
Code to set options
just call setOptions in next previous with index of question.
I used
index-1as arraylist start with 0 So it depends on you how you use index.This way you can set first options Also in you function which you will call on next button click use above line of code to set next