这是我的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);
}
}
});
}
}
如何在我的第二个 Activity 中显示单击的单选按钮值?
非常感谢您的帮助,谢谢。
最佳答案
将值作为 Intent 传递
Intent intent = new Intent(youractivity.this,secondactivity.class);
intent.putExtra("key",radiobutton.getText());
startActivity(intent);
在第二个 Activity 中访问它
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
关于java - 如何在 android studio 中的第二个 Activity 中显示单击的单选按钮值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50561278/