0

我有

<RadioGroup
    android:id="@+id/sign_up_select_colour"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"

    <RadioButton
        android:id="@+id/rdbtn_red"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/red" />

    <RadioButton
        android:id="@+id/rdbtn_blue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/blue" />
</RadioGroup>

我想以与此处使用 EditText 相同的方式将字符串blue发送到下一个活动(在您之前的帮助下);

EditText editTextSignUpUserName = (EditText) findViewById(R.id.sign_up_user_name);
String signUpUserName = editTextSignUpUserName.getText().toString();
intent.putExtra("username", signUpUserName);

我试过这个;

RadioButton selectedRadioButton = (RadioButton)   findViewById(R.id.sign_up_select_colour);
String signUpColour = selectedRadioButton.getCheckedRadioButtonText().toString();
intent.putExtra("colour", signUpColour);

请和谢谢。

4

1 回答 1

1

好的,你快到了。但是 RadioGroup 不是 RadioButton。试试这个:

RadioGroup colourGroup = (RadioGroup) findViewById(R.id.sign_up_select_colour);
RadioButton button = (RadioButton) colourGroup.findViewById(colourGroup.getCheckedRadioButtonId());
String signUpColour = button.getText().toString();
intent.putExtra("gender", signUpColour);
于 2012-09-03T21:06:52.643 回答