Calling a Method from button click
<p>I'm new to java and I'm trying to run a method once a button is clicked and I am unsure if I'm on the right track. I am selecting 10 questions from a Sqlite database and would like to cycle through each question 0-9 everytime the button is clicked. Once all 10 questions are asked I will move to another activity. I have the app displaying the first question fine but I am having trouble calling the showQuestions method and increasing the questionNum int by one when the button is clicked and passing this onto the method. Any help would be appreciated!</p>

<p>This is the showQuestions method which I am trying to call.</p>

<pre><code>public void showQuestions(Cursor cursor) {
    cursor.moveToPosition(questionNum);
    while (cursor.moveToNext()) {
        // Collect String Values from Query
        StringBuilder questiontxt = new StringBuilder("");
        StringBuilder answertxt1 = new StringBuilder("");
        StringBuilder answertxt2 = new StringBuilder("");
        StringBuilder answertxt3 = new StringBuilder("");
        StringBuilder answertxt4 = new StringBuilder("");
        String question = cursor.getString(2);
        String answer = cursor.getString(3);
        String option1 = cursor.getString(4);
        String option2 = cursor.getString(5);
        String option3 = cursor.getString(6);
        questiontxt.append(question).append("");
        answertxt1.append(answer).append("");
        answertxt2.append(option1).append("");
        answertxt3.append(option2).append("");
        answertxt4.append(option3).append("");
    }
}
</code></pre>

<p>This is the code for the button which I am working on. There are 4 buttons.</p>

<pre><code>public void onClick(View v) {
    switch (v.getId()) {

        case R.id.option1_button:
        if (questionNum&lt;9) {
            questionNum ++;
        }
        Questions.this.showQuestions(null);
        break;
    }
</code></pre>

<p>And this is the XML code for the buttons.</p>

<pre><code>&lt;Button
    android:id="@+id/option1_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/option3_button"/&gt;
</code></pre>

<p>OnClick Listener for the button</p>

<pre><code>View option1_button = findViewById(R.id.option1_button);
option1_button.setOnClickListener(this);
</code></pre>

<p>Database Query and Allocation to Cursor</p>

<pre><code>//Get the questions and allocate them to the Cursor
public Cursor getQuestions() {
//Select Query 
String loadQuestions = "SELECT * FROM questionlist ORDER BY QID LIMIT 10";
SQLiteDatabase db = questions.getReadableDatabase();
Cursor cursor = db.rawQuery(loadQuestions, null);
startManagingCursor(cursor);
return cursor;
}
</code></pre>

<p>Thanks in advance.</p>
