title: How to create a back button in quiz app?
body: <pre><code> public class MainActivity extends AppCompatActivity {
               List&lt;Questions&gt; quesList;
               int score=0;
               int qid=0;
              Questions currentQ;
              TextView tv;
              RadioButton rb1,rb2,rb3,rb4;
              ImageButton next,back;
              Questions cur;
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_main);
                  DbHelper db=new DbHelper(this);
                  final RadioGroup grp=(RadioGroup) findViewById(R.id.radiogroup1);
                  quesList=db.getAllQuestions();
                  if(quesList!= null &amp;&amp; quesList.size() !=0) {
                      currentQ=quesList.get(qid);
                  }
                  tv=(TextView) findViewById(R.id.tv1);
                  rb1=(RadioButton) findViewById(R.id.radio1);
                  rb2=(RadioButton) findViewById(R.id.radio2);
                  rb3=(RadioButton) findViewById(R.id.radio3);
                  rb4=(RadioButton) findViewById(R.id.radio4);
                  next=(ImageButton) findViewById(R.id.forward);
                  back=(ImageButton) findViewById(R.id.backward);
                  setQuestionView();
  
        //code for next button..      
  
      next.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
  
                      RadioButton answer=(RadioButton) findViewById(grp.getCheckedRadioButtonId());
  
                      if(currentQ.getAnswer().equals(answer.getText()))
                      {
                          score++;
                          Log.d("score", "Your score" + score);
                      }
                      if(qid&lt;5){
                          currentQ=quesList.get(qid);
                          setQuestionView();
  
                          qid++;
                          grp.clearCheck();
                      }else{
                          Intent intent = new Intent(MainActivity.this, ResultActivity.class);
                          Bundle b = new Bundle();
                          b.putInt("score", score); //Your score
                          intent.putExtras(b); //Put your score to your next Intent
                          startActivity(intent);
                          finish();
                      }
                  }
              });
              back.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                  //Below is the code, i wrote for previous button
                    but it is not working please help me.   
                       if(qid&lt;5)
              {
                  currentQ=quesList.get(qid);
                  setQuestionView();
                  qid--;
              }
                  }
              });
          }
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.menu_main, menu);
              return true;
          }
          private void setQuestionView()
          {
              tv.setText(currentQ.getQuestion());
              rb1.setText(currentQ.getOption1());
              rb2.setText(currentQ.getOption2());
              rb3.setText(currentQ.getOption3());
              rb4.setText(currentQ.getOption4());
  
          }
  
  
  
      }
  </code></pre>
  
  <p>What I want to create is  back button in my quiz app, the questions come from database. I want button to go to previous question without messing up.I am new to android can any one help me to solve the problem..</p>