java - 如何在 android studio 中的第二个 Activity 中显示单击的单选按钮值?

标签 java android

这是我的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/

相关文章:

java - 如何将字符串转换为日期 (HHMMMDD)(小时、月份、日期)

java - Apache Spark (Java) 中列的自定义处理

java - 通用 BinarySearchTree 中的 PostOrder 输出 (Java)

android - 获取 java.lang.NoSuchMethodError,没有虚拟方法日志(ILjava/lang/String;Ljava/lang/Throwable;)

安卓SDK : Playing video using mms protocol

java - 查询中的字符串参数

java - Hibernate 批量更新与存储过程

android - 在 sleep 模式下未收到 UDP 广播数据包

android - 启动不支持多窗口的新 Activity

java - 使用单例 MainActivity?