第一步,還是創建android專案。
第二步,修改已產生的res/layout/main.xml
view plaincopy to clipboardprint?
android:orientation="vertical"
"
>
android:id="@+id/checkBox" android:layout_height="wrap_content" android:text="複選框1" /> android:id="@+id/checkBox1"
" android:layout_height="wrap_content" android:text="上海" /> io+ RadioButton r1 = null; RadioButton r2 = null; RadioButton r3 = null; RadioButton r4 = null; @Override public void onCreate ate(savedInstanceState); setContentView(R.layout.main); CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox); CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1); //取得單選按鈕組 RadioGroup radioGroup (RadioGroup); //取得單選按鈕 r1 = (RadioButton )findViewById(R.id.radion1); r2 = (RadioButton )findViewById(R.id.radion2); r3 = (RadioButton )findViewById(R.id.radion3); r4 = (RadioButton )findViewById(R.id.radion4); checkBox.setChecked(true); r1.setClickable(true); //監聽多重選擇按鈕 checkBox.setOnCheckedChangeListener(this); checkBox1.setOnCheckedChangeListener(this); //監聽單選按鈕 radioGroup.setOnCheckedChangeListenerener(mChangeRadio); }