-1

I want to put my own score from first activity and I'm using a checkbox method. By selecting that checkbox, they have their own score which is one. After selecting that checkbox and press button next, it will go to the next activity which contain that score 1. Then the process in this second activity do the same as the first activity, but the only different is that the score must increase by 1. I will show my work on first activity below:

public class AfterNoYesQ1Activity extends AppCompatActivity {

Button buttonNext;

TextView textViewClickHere;




int score = 1;


CheckBox check1,check2,check3,check4,check5,check6,check7;

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

    check1 = (CheckBox)findViewById(R.id.checkBox1);
    check2 = (CheckBox)findViewById(R.id.checkBox2);
    check3 = (CheckBox)findViewById(R.id.checkBox3);
    check4 = (CheckBox)findViewById(R.id.checkBox4);
    check5 = (CheckBox)findViewById(R.id.checkBox5);
    check6 = (CheckBox)findViewById(R.id.checkBox6);
    check7 = (CheckBox)findViewById(R.id.checkBox7);


    buttonNext = (Button)findViewById(R.id.buttonNext);

    buttonNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {



            Intent intent = new Intent(AfterNoYesQ1Activity.this, DetectionQues2Activity.class);
            startActivity(intent);



        }
    });


    textViewClickHere = (TextView) findViewById(R.id.textViewClickHere);

    textViewClickHere.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(AfterNoYesQ1Activity.this, DetectionQues2Activity.class);
            startActivity(intent);




        }
    });


}

public void checkone (View view)

{

    if (check1.isChecked() && check5.isChecked() && check6.isChecked())
    {


        getIntent().putExtra("score",score);


    }
    else if (check1.isChecked() && check5.isChecked() && check7.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check1.isChecked() && check6.isChecked() && check7.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check2.isChecked() && check5.isChecked() && check6.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check2.isChecked() && check5.isChecked() && check7.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check2.isChecked() && check6.isChecked() && check7.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check3.isChecked() && check5.isChecked() && check6.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check3.isChecked() && check5.isChecked() && check7.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check3.isChecked() && check6.isChecked() && check7.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check3.isChecked() && check5.isChecked() && check6.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check3.isChecked() && check5.isChecked() && check7.isChecked())
    {
        //fail
        getIntent().putExtra("score",score);

    }
    else if (check1.isChecked() && check5.isChecked() && check6.isChecked())
    {

    }
    else if (check3.isChecked() && check6.isChecked() && check7.isChecked())
    {
        //fail

    }
    else if (check1.isChecked() && check2.isChecked() && check5.isChecked())
    {
        //pass

    }
    else if (check1.isChecked() && check2.isChecked() && check6.isChecked())
    {
        //pass

    }
    else if (check1.isChecked() && check2.isChecked() && check7.isChecked())
    {
        //pass

    }
    else if (check1.isChecked() && check2.isChecked() && check3.isChecked() && check5.isChecked())
    {
        //pass

    }
    else if (check1.isChecked() && check2.isChecked() && check3.isChecked() && check6.isChecked())
    {
        //pass

    }
    else if (check1.isChecked() && check2.isChecked() && check3.isChecked() && check7.isChecked())
    {
        //pass

    }
    else if (check1.isChecked() && check2.isChecked() && check3.isChecked()
            && check4.isChecked() && check5.isChecked())
    {
        //pass

    }
    else if (check1.isChecked() && check2.isChecked() && check3.isChecked()
            && check4.isChecked() && check6.isChecked())
    {
        //pass

    }
    else if (check1.isChecked() && check2.isChecked() && check3.isChecked()
            && check4.isChecked() && check7.isChecked())
    {
        //pass

    }



    score = score + 1;

}

}
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
jatt
  • 1
  • Where are you calling the checkone() method? – ILLIA DEREVIANKO Nov 02 '18 at 11:50
  • This you know that you can [putExtra](https://stackoverflow.com/questions/5265913/how-to-use-putextra-and-getextra-for-string-data) information to intents and getExtra from incoming intents? – kelalaka Nov 02 '18 at 11:50
  • i literally know about putExtra information and get in on the next activity using button. but i cant figue it out on how to putExtra for checkbox, or else i cant use the method checkone? – jatt Nov 02 '18 at 11:56
  • Try to make your `chackone()` method return **Boolean** value, where you are deciding Pass & Fail, and based on the value from `checkone()` method do `putExtra()` where you are passing your intent to next Activity. – Danger Nov 02 '18 at 12:35

2 Answers2

1

If I understand correctly, you want to pass the current score modified by checkboxes from AfterNoYesQ1Activity to DetectionQues2Activity?

If that's the case, instead of using getIntent().putExtra in checkone, modify your textViewClickHere.onClickListener to:

textViewClickHere.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        Intent intent = new Intent(AfterNoYesQ1Activity.this, DetectionQues2Activity.class);
        intent.putExtra("score", score);
        startActivity(intent);
    }
});

getIntent().putExtra simply gets and modifies the Intent of the current activity (AfterNoYesQ1Activity) and will not be passed to the next activity.

If I'm missing the point please rephrase your question as it's incredibly hard to decipher.

wabbawabbe
  • 105
  • 8
  • yes correct.. but if i put intent.putExtra ("score",score) on my textViewClickHere.onClickListener will it pass that score on the checkbox as well? Because i am confused how to pass the data (score) properly, because if the checkbox 1,2,3 is selected, they will get score 1, and that score 1 i want to pass to the next activity. – jatt Nov 02 '18 at 14:07
0

According to the documentation,

getIntent() Return the intent that started this activity.

I think then that you must have an instance of score as an attribute of your activity. Your method checkone() could increment your score and when you click on the next button, you have to pass the score as an extra of the intent. As @wabbawabbe showned