ラジオグループ(複数のラジオボタンをグループ化したもの)内の指定したIDのラジオボタンのチェックを設定する.
- findViewByIdメソッドで, 指定したリソースインデックスのIDに対応したラジオグループのインスタンスを取得する.
- checkメソッドで, 指定したIDのラジオボタンのチェックをセットする.
package com.moonlight_aska.android.radiobutton01;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class RadioButton01 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RadioGroup group = (RadioGroup)findViewById(R.id.radiogroup_id);
group.check(R.id.radiobutton_id02);
}
}