Connect random chosen category to equivalent database question table

  • Replies:0
DRoszhart
  • Forum posts: 3

Apr 17, 2017, 11:36:32 PM via Website

Hello,
I am running into a problem with connecting my random chosen category with the equivalent database question table. I have an array of items and one is randomly picked and if that one is equivalent with the chosen an intent is sent transitioning to next activity

 public void onClick(View arg0) {

            String[] mycategory = {"Who", "What", "When", "Where", "Why"};
            int i = new Random().nextInt(mycategory.length);
            TextView textView = (TextView) findViewById(R.id.Category_Result);
            textView.setText(mycategory[i]);
            if (mycategory[i].equals("Who") ) {

                Intent myIntent= new Intent(CategoryActivity.this, QuestionActivity.class);
                myIntent.putExtra("mycategory", "Who");
            }
            if (mycategory[i].equals("What")) {
                Intent myIntent= new Intent(CategoryActivity.this, QuestionActivity.class);
                myIntent.putExtra("mycategory", "What");
                startActivity(myIntent);
            }

And here it is compared in an if else statement. If it is right with one of those then it will run through the code. The problem is that when I get to this next activity only the buttons show up and not the correct corresponding questions. Any help is appreciated.

 public void onClickQuestion(View v) {
    Bundle c = getIntent().getExtras();
        mySelectedCategory = c.getString("mycategory");

    if (mySelectedCategory.equals("Who")) {
        setQuestionView();
        switch (v.getId()) {
            case R.id.btnOptionA:
                if (currentWhoQ.getAnswer().equals(btnA.getText())) {
                    score++;
                }
                if (qid < 10) {
                    currentWhoQ = whoQuesList.get(qid);
                    setQuestionView();
                } else {
                    Intent intent = new Intent(QuestionActivity.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);
                }
                break;

            case R.id.btnOptionB:
                if (currentWhoQ.getAnswer().equals(btnB.getText())) {
                    score++;
                }
                if (qid < 10) {
                    currentWhoQ = whoQuesList.get(qid);
                    setQuestionView();

                } else {
                    Intent intent = new Intent(QuestionActivity.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);

                }

                break;
            case R.id.btnOptionC:
                if (currentWhoQ.getAnswer().equals(btnC.getText())) {
                    score++;
                }

                if (qid < 10) {
                    currentWhoQ = whoQuesList.get(qid);
                    setQuestionView();
                } else {
                    Intent intent = new Intent(QuestionActivity.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);

                }
                break;
            case R.id.btnOptionD:
                if (currentWhoQ.getAnswer().equals(btnD.getText())) {
                    score++;
                }
                if (qid < 10) {
                    currentWhoQ = whoQuesList.get(qid);
                    setQuestionView();
                } else {
                    Intent intent = new Intent(QuestionActivity.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);
                }
                break;

        }
    } else if (mySelectedCategory.equals("What")); {
        setWhatQuestionView();
        switch (v.getId()) {
            case R.id.btnOptionA:
                if (currentWhatQ.getAnswer().equals(btnA.getText())) {
                    score++;
                }
                if (qid < 10) {
                    currentWhatQ = whatQuesList.get(qid);
                    setQuestionView();
                } else {
                    Intent intent = new Intent(QuestionActivity.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);

                }
                break;

            case R.id.btnOptionB:
                if (currentWhatQ.getAnswer().equals(btnB.getText())) {
                    score++;
                }
                if (qid < 10) {
                    currentWhatQ = whatQuesList.get(qid);
                    setQuestionView();

                } else {
                    Intent intent = new Intent(QuestionActivity.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);

                }

                break;

            case R.id.btnOptionC:
                if (currentWhatQ.getAnswer().equals(btnC.getText())) {
                    score++;
                }

                if (qid < 10) {
                    currentWhatQ = whatQuesList.get(qid);
                    setQuestionView();
                } else {
                    Intent intent = new Intent(QuestionActivity.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);

                }

                break;

            case R.id.btnOptionD:
                if (currentWhatQ.getAnswer().equals(btnD.getText())) {
                    score++;
                }
                if (qid < 10) {
                    currentWhatQ = whatQuesList.get(qid);
                    setQuestionView();
                } else {
                    Intent intent = new Intent(QuestionActivity.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);

                }
                break;
        }

Reply