Hi,

I am a beginner and I am stuck whilst developing a simple quiz
application in android. The code is below. onClick next button is not
displaying the next random question. Any help?

package com.quiz;

import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class Quiz2Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Random r = new Random();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final String[] Countries =
{"India","U.S","Singapore","Malaysia","Sri
Lanka","Thailand","Indonesia","China","Japan","Korea","Vietnam"};
        final String[] Capitals = {"Delhi","Washington D.C","Singapore
City","Kaula lampur", "Colombo",
"Bangkok","Jakarta","Beiing","Tokyo","Seoul","Ho Chi Min City"};
        String question;
        RadioGroup rg1 = (RadioGroup)findViewById(R.id.rg1);
        Button but1 = (Button) findViewById(R.id.but1);
        for(int i=0;i<4;i++){
                int num = r.nextInt(10);
                question = "Whats the capital of the country " +
Countries[num];
                TextView Question = (TextView) findViewById(R.id.ques);
                Question.setText(question);
                RadioButton ans1 = (RadioButton) findViewById(R.id.ans1);
                RadioButton ans2 = (RadioButton) findViewById(R.id.ans2);
                RadioButton ans3 = (RadioButton) findViewById(R.id.ans3);
                RadioButton ans4 = (RadioButton) findViewById(R.id.ans4);
                ans1.setText(Capitals[num+1]);
                ans2.setText(Capitals[num]);
                ans3.setText(Capitals[num+2]);
                ans4.setText(Capitals[num-2]);

        }
        but1.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                                finish();
                                Bundle tempbundle = new Bundle();
                                onCreate(tempbundle);
                        }
                });
    }
}

I suspect but1.setOnClickListener method.

Regards,
Subbu

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to