Sending radio button data to next activity

后端 未结 2 1278
臣服心动
臣服心动 2021-01-19 08:10

I\'m trying to allow the user to enter their Name, and click on one of three radio buttons, and click on a submit button. And on the next activity, it will display their nam

2条回答
  •  执念已碎
    2021-01-19 08:41

    String str; // store the text corresponding to  the RadioButton which is clicked 
    
       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, WinderDTActivity.class);
                intent.putExtra("radioChosen", str); // pass "str" to the next Activity
    

    EDIT : To recieve the data in the next activity, use

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String message= extras.getString("radioChosen");
    
    }
    

提交回复
热议问题