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 に答える