Java 如何在android studio中的第二个活动中显示单击的单选按钮值?

Java 如何在android studio中的第二个活动中显示单击的单选按钮值?,java,android,Java,Android,这是我的java代码: public class jenis extends AppCompatActivity { public Button button3; RadioGroup radioGroup2; RadioButton radioButton2; DatabaseReference databaseReference; @Override protected void onCreate(Bundle savedInstanceS

这是我的java代码:

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);
                }
            }
        });
    }

}
如何在第二个活动中显示单击的单选按钮值


非常感谢您的帮助,谢谢。

将此值作为意图传递

 Intent intent = new Intent(youractivity.this,secondactivity.class);
 intent.putExtra("key",radiobutton.getText());
 startActivity(intent);
在第二个活动中访问它

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

 you can also store your radiobutton checked value in shared preference and 
  then access it on another activity... It will work like session

我遗漏了什么?

使用Intent将一个活动的值传递给另一个活动。单击单选按钮的值可能与您所指的重复?您是指被选中的
true
,还是指
RadioButton
的文本标签?如果您是指将单击按钮的值传递给另一个活动,请使用
intent
,或者只需存储在变量中并在另一个活动中访问该变量。
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");
   }

}