XMLの記載
RadioGroupで囲むと排他選択になる
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@+id/radioButton"
android:layout_alignParentStart="true">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Xxx"
android:id="@+id/radioButton"
android:layout_below="@+id/textView"
android:layout_alignParentStart="true"
android:layout_marginTop="42dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yyy"
android:id="@+id/radioButton2"
android:layout_below="@+id/radioButton"
android:layout_alignParentStart="true" />
</RadioGroup>
java側は以下
1. ハンドラの登録
// ラジオボタンハンドラ
RadioButton rbuttonXxx = (RadioButton)findViewById(R.id.radioButton);
rbuttonXxx.setOnClickListener(new RadioButtonXxxClickListener());
2. ハンドラを記載
private class RadioButtonXxxClickListener implements View.OnClickListener {
@Override
public void onClick(View v){
// 処理の内容を書く
}
0 件のコメント:
コメントを投稿