<RadioGroup
android:id="@+id/query_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checkedButton="@+id/query_type_fuzzy"
android:orientation="horizontal" android:gravity="center_vertical|center_horizontal">
<RadioButton
android:id="@+id/query_type_fuzzy"
android:text="fuzzy"
/>
<RadioButton
android:id="@+id/query_type_precise"
android:text="precise"
/>
</RadioGroup>
<TableLayout
android:id="@+id/test_tabel_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TableRow android:gravity="center_vertical|center_horizontal">
<Button
android:id="@+id/button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_ok"/>
<Button
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_cancel"/>
</TableRow>
</TableLayout>
<TableLayout
android:id="@+id/test_tabel_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" android:visibility="gone">
<TableRow android:gravity="center_vertical|center_horizontal">
<TextView
android:text="page 2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</TableRow>
</TableLayout>
RadioGroup rg = (RadioGroup).findViewById(R.id.query_type);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
Log.i(TAG, "RadioGroop: " + checkedId);
TableLayout tl1 = (TableLayout)dialog.findViewById(R.id.test_tabel_1);
TableLayout tl2 = (TableLayout)dialog.findViewById(R.id.test_tabel_2);
if(R.id.query_type_fuzzy == checkedId){
tl1.setVisibility(TableLayout.VISIBLE);
tl2.setVisibility(TableLayout.GONE);
}else if(R.id.query_type_precise == checkedId){
tl2.setVisibility(TableLayout.VISIBLE);
tl1.setVisibility(TableLayout.GONE);
}
}
});
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_checked="true"
android:drawable="@drawable/checked" />
<item android:state_enabled="true" android:state_checked="false"
android:drawable="@drawable/unchecked" />
</selector>
check和checknull分别为选中和位选中的图片。
1 | 然后在你的布局文件中,RadioButton 布局 |
1 | 设置android:button = "@drawable/radiobutton" ,就可以了! |