Pass values from one activity (radiobutton) to another activity

0

Good, I have a problem I want to pass the data of a radiobutton that are in two activitys, one is called sumaActivity and the other restaActivity different to another activity that is called resultadoActivity

sumaActivity

  public class sumaActivity extends AppCompatActivity {

    TextView txtpregunta;
    RadioButton rbtna,rbtnb,rbtnc,rbtnd;
    Button btnatras,btnsiguiente;
    RadioGroup rdgroup;

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

        rdgroup = (RadioGroup) findViewById(R.id.rdgroup);
        txtpregunta = (TextView) findViewById(R.id.txtpregunta);
        rbtna = (RadioButton) findViewById(R.id.rbtna);
        rbtnb = (RadioButton) findViewById(R.id.rbtnb);
        rbtnc = (RadioButton) findViewById(R.id.rbtnc);
        rbtnd = (RadioButton) findViewById(R.id.rbtnd);
        btnatras= (Button) findViewById(R.id.btnatras);
        btnsiguiente= (Button) findViewById(R.id.btnsiguiente);

        btnsiguiente.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(getApplicationContext(),restaActivity.class);
                startActivity(i);
            }
        });

        rdgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                if (checkedId == R.id.rbtna){

                }else if (checkedId == R.id.rbtnb){

                }else if (checkedId == R.id.rbtnc){

                }else if (checkedId == R.id.rbtnd){

                }
            }
        });
    }

restaActivity

  public class restaActivity extends AppCompatActivity {

    TextView txtpregunta;
    RadioButton rbtna,rbtnb,rbtnc,rbtnd;
    Button btnatras,btnsiguiente;
    RadioGroup rdgroup;

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

        rdgroup = (RadioGroup) findViewById(R.id.rdgroup);
        btnsiguiente = (Button) findViewById(R.id.btnsiguiente);

        btnsiguiente.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(getApplicationContext(),ResultadoActivity.class);
                startActivity(i);
            }
        });

        rdgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                if (checkedId == R.id.rbtna){

                }else if (checkedId == R.id.rbtnb){

                }else if (checkedId == R.id.rbtnc){

                }else if (checkedId == R.id.rbtnd){

                }
            }
        });

    }

}

And my% co_of% that is empty, What I want is that when selecting an option of resultadoActivity of radiobutton and an option of sumaActivity of radiobutton is displayed in restaActivity what you have selected

    
asked by kevvelas 01.12.2017 в 03:38
source

1 answer

1

For activity add or subtract is the same procedure

This is how we send the data

public void onRadioButtonClicked(View view) {
    String str; // variable donde se almacenara el dato del radioButton

       switch(view.getId()) {
                    case R.id.radioButton1:
                        if (checked)
                         str = "button1Text";
                            break;
                    case R.id.radioButton2:
                        if (checked) str = "button2Text";
                            break;
                    case R.id.radioButton3:
                        if (checked) str = "button3Text";
                            break;
             }
  } 


            Intent intent = new Intent(this, resultadoActivity.class);
            intent.putExtra("radioChosen", str); // enviaras lo que contiene str a la siguiente Activity

And to receive the content of str in the result activity:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String message= extras.getString("radioChosen");// radioChosen es el ID que le dimos a str. 

}
    
answered by 01.12.2017 в 04:54