0

This is my java code:

public class jenis extends AppCompatActivity {

    public Button button3;
    RadioGroup radioGroup2;
    RadioButton radioButton2;
    DatabaseReference databaseReference;

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

        radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
        databaseReference = FirebaseDatabase.getInstance().getReference();

        final RadioButton stock = (RadioButton)findViewById(R.id.radioButton11);
        final RadioButton property = (RadioButton)findViewById(R.id.radioButton12);

        button3 = (Button) findViewById(R.id.button3);
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (stock.isChecked()){
                    Variable newVar = new Variable();
                    newVar.setAmountt("jeniss");
                    databaseReference.child(newVar.getAmountt()).setValue("Stock Waqf");
                }

                else if(property.isChecked()){
                    Variable newVar = new Variable();
                    newVar.setAmountt("jeniss");
                    databaseReference.child(newVar.getAmountt()).setValue("Property Waqf");
                }

                if(stock.isChecked()){
                    Intent intent = new Intent(jenis.this, stock.class);
                    startActivity(intent);
                }

                if(property.isChecked()){
                    Intent intent = new Intent(jenis.this, property.class);
                    startActivity(intent);
                }
            }
        });
    }

}

How can I display the clicked radio button value on my second activity?

I really appreciate your help, thank you.

J-Alex
  • 6,881
  • 10
  • 46
  • 64
  • Pass the value one activity to another using Intent.. – Amit May 28 '18 at 07:33
  • 2
    Possible duplicate of [How do I pass data between Activities in Android application?](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – Amit May 28 '18 at 07:34
  • What do you mean by *clicked radio button value*? Do you mean `true` because it is checked or do you mean the text label of the `RadioButton`? – deHaar May 28 '18 at 07:59
  • If you mean passing clicked button's value to another activity, use `intent`, or just store in a variable and access the variable in another activity. – hatched May 28 '18 at 08:15

2 Answers2

1

pass the value as intent

 Intent intent = new Intent(youractivity.this,secondactivity.class);
 intent.putExtra("key",radiobutton.getText());
 startActivity(intent);

to access it on second activity

in OnCreate() method
    getIntent().getStringExtra("key");

or else

 you can also store your radiobutton checked value in shared preference and 
  then access it on another activity... It will work like session
deHaar
  • 17,687
  • 10
  • 38
  • 51
primo
  • 1,340
  • 3
  • 12
  • 40
0
public class stock extends AppCompatActivity {
DatabaseReference databaseReference;


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

    final TextView textViewOut = (TextView) findViewById(R.id.textViewOut2);


    textViewOut.setText(" ");


}

public void OnCreate() {
    getIntent().getStringExtra("jeniss");
   }

}

what did i missed ?

Nikunj Paradva
  • 15,332
  • 5
  • 54
  • 65