Jump to content

Hey guys, 

So I have an answers array consisting of "True" and "False" and I have two buttons on the main form, now I want to check if a button is pressed, if the text on the button is the same as the answer for that specific question. If it is, then i want to load up the next question, if not then i will just have a toast pop up or something. I'm currently struggling and I don't even know where to start for this, because I don't know how to know which button was clicked and which to check.

This is currently all the code I have:

 

public class Question extends AppCompatActivity {
//declare variables
    private String[] QuestionsArr = {"This bird is blue", "question 2....z"}; //10 questions will go here
    private String[] AnswersArr = {"True", "False"};
    int questionNum = 0;
    int count =1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_questions);
    }

    public void SetQuestions()
    {
        //right the question to the text view, this is called if answer is answered correctly. starts at 1, because original question will be set to 0.
        for (int i = 1; i <= QuestionsArr.length; i++)
        {
            //change the question number
            TextView quest = (TextView) findViewById(R.id.Question_Txt);
            quest.setText(QuestionsArr[questionNum]);
            questionNum++;
            //increment question number indicator
            TextView questNum = (TextView) findViewById(R.id.QuestNum_Text);
            count ++;
            questNum.setText("Question" + count);

        }
    }

    public void CheckQuestions()
    {
        if(questionNum <= QuestionsArr.length)
        {
            if(//check the button press in here to see if answer is correct)
            {
              //call set questions to load next question.
            }
        }
    }

 

Any help would be greatly appreciated, thanks. :)

Link to comment
https://linustechtips.com/topic/610965-android-studio-truefalse-buttons-help/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×