Android RadioButton class three kinds of checked way

来源:互联网 发布:网络安全法宣传单内容 编辑:程序博客网 时间:2024/05/17 23:54

The first : main.xml file,RadioButton element add android:checked attribute, set "true";

The second : use setChecked() on the RadioButton from within your onCreate() callback in your activity.example:

    RadioButton rb = (RadioButton)findViewById(R.id.radio1);

    rb.setChecked(true);

The third:use check() on the RadioGroup from within your onCreate() callback in your activity.example:

    RadioGroup rg = (RadioGroup)findViewById(R.id.radiogroup);

    rg.check(R.id.radio2);

原创粉丝点击