默认显示选中的RadioButton的内容,android

默认显示选中的RadioButton的内容,android,android,radio-button,Android,Radio Button,在我的活动中,我水平设置了三个单选按钮。对于每个单选按钮,我设置了一些复选框和一个按钮,每个单选按钮都不同 <RadioGroup android:id="@+id/selection" android:layout_width="fill_parent" android:weightSum="3" android:layout_height="fill_parent" and

在我的活动中,我水平设置了三个单选按钮。对于每个单选按钮,我设置了一些复选框和一个按钮,每个单选按钮都不同

 <RadioGroup
                    android:id="@+id/selection"
            android:layout_width="fill_parent"
            android:weightSum="3"
            android:layout_height="fill_parent" android:orientation="horizontal">
        <RadioButton

                android:layout_width="fill_parent"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Sensation"
                android:id="@+id/sens" android:checked="true"/>
        <RadioButton
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="Location"
                  android:layout_weight="1"
                android:id="@+id/loc" android:checked="false"/>
        <RadioButton
                android:layout_width="fill_parent"
                  android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Modalation"
                android:id="@+id/mod" android:checked="false"/>
    </RadioGroup>

现在,我希望在默认情况下选中我的第一个radiobutton,并在活动开始时显示其相关内容。但是默认情况下,我无法显示相关内容。它仅在我选择其他单选按钮并重新选择时显示。我想这是因为OnCheckChangeListener,我们是否有其他radioButton事件,通过这些事件,选中的radioButton的内容可以默认显示?

您使用什么来显示相关内容?文本视图

我认为您应该为视图设置一个默认内容,每当选中单选按钮时,您都可以通过onRadioButtonClicked函数更新视图的内容

编辑:

一,。 将默认内容设置为textView,并将三个单选按钮中的一个选中为默认。我想你已经做到了

二,。 为每个单选按钮设置onclick事件,如下所示:

...
<RadioButton android:id="@+id/radio_btn_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="radio_btn_1"
        android:onClick="onRadioButtonClicked"/>
...

是,文本视图和复选框。其中,每个单选按钮的文本视图不同。你能举例说明你的答案吗?
...
public void onRadioButtonClicked(View view) {
    // Is the button now checked?
    boolean checked = ((RadioButton) view).isChecked();
    TextView textView = (TextView) findViewById(R.id.textView);

    // Check which radio button was clicked
    switch(view.getId()) {
        case R.id.radio_btn_1:
            if (checked)
                textView.setText('your content for btn 1');
            break;
        case R.id.radio_btn_2:
            if (checked)
                textView.setText('your content for btn 2');
            break;
    }
}
...