主要关注onCheckedChangeListener方法~
public class ConferenceActivity extends BaseActivity implements OnCheckedChangeListener{
public static final String TAG = "ConferenceActivity";
//function moudle
private RadioGroup mRgConfFunctionModule1;
private RadioGroup mRgConfFunctionModule2;
//used to deal with radio button checked state
private Boolean changeGroup = false;
private Context mCtx;
private ConfAccount mConfAccount;
//user checked id
private int mCheckedId = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conference_main);
initView();
}
private void initView() {
mCtx = this;
mRgConfFunctionModule1 = (RadioGroup) findViewById(R.id.rg_function_moudle_1);
mRgConfFunctionModule2 = (RadioGroup) findViewById(R.id.rg_function_moudle_2);
mRgConfFunctionModule1.setOnCheckedChangeListener(this);
mRgConfFunctionModule2.setOnCheckedChangeListener(this);
long id = getIntent().getLongExtra(Constant.KEY_OF_CONF_ACCOUNT_ID, -1L);
mConfAccount = AppClass.getInstance().getAccountById(id);
if (!Util.isEmpty(mConfAccount)) {
setTitleName(mConfAccount.getConfAccountName());
}
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (group != null && checkedId > -1 && changeGroup == false){
if(group == mRgConfFunctionModule1){
changeGroup = true;
mRgConfFunctionModule2.clearCheck();
changeGroup = false;
}else if(group == mRgConfFunctionModule2){
changeGroup = true;
mRgConfFunctionModule1.clearCheck();
changeGroup = false;
}
mCheckedId = checkedId;
}
}
public void addParticipant() {
Util.startActivity(mCtx, AddParticipantActivity.class);
}
public void onRadioClick(View v) {
int id = v.getId();
switch (mCheckedId) {
case R.id.rb_open_hf:
//Util.shortToast(this, "hf");
break;
case R.id.rb_self_mute:
Util.shortToast(this, "self mute");
break;
case R.id.rb_mute_all:
Util.shortToast(this, "mute all");
break;
case R.id.rb_call_name:
Util.shortToast(this, "call name");
break;
case R.id.rb_record:
Util.shortToast(this, "record");
break;
case R.id.rb_add_participant:
// Util.shortToast(this, "add");
addParticipant();
break;
case R.id.rb_lock:
Util.shortToast(this, "lock");
break;
case R.id.rb_other_function:
Util.shortToast(this, "other");
break;
}
}
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical" >
<include
android:id="@+id/title"
layout="@layout/title_layout" />
<RadioGroup
android:id="@+id/rg_function_moudle_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:background="@color/white"
android:orientation="horizontal"
android:>
<RadioButton
android:id="@+id/rb_open_hf"
style="@style/RadioButtonStyle"
android:drawableTop="@android:drawable/btn_radio"
android:text="@string/conf_open_hf" />
<RadioButton
android:id="@+id/rb_self_mute"
style="@style/RadioButtonStyle"
android:drawableTop="@android:drawable/btn_radio"
android:text="@string/conf_mute_self" />
<RadioButton
android:id="@+id/rb_mute_all"
style="@style/RadioButtonStyle"
android:drawableTop="@android:drawable/btn_radio"
android:text="@string/conf_mute_all" />
<RadioButton
android:id="@+id/rb_call_name"
style="@style/RadioButtonStyle"
android:drawableTop="@android:drawable/btn_radio"
android:text="@string/conf_call_name" />
<RadioButton
android:id="@+id/rb_record"
style="@style/RadioButtonStyle"
android:drawableTop="@android:drawable/btn_radio"
android:text="@string/conf_record" />
</RadioGroup>
<RadioGroup
android:id="@+id/rg_function_moudle_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="15dp"
android:background="@color/white"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rb_add_participant"
style="@style/RadioButtonStyle"
android:drawableTop="@android:drawable/btn_radio"
android:text="@string/conf_add_participant" />
<RadioButton
android:id="@+id/rb_lock"
style="@style/RadioButtonStyle"
android:drawableTop="@android:drawable/btn_radio"
android:text="@string/conf_lock" />
<RadioButton
android:id="@+id/rb_other_function"
style="@style/RadioButtonStyle"
android:drawableTop="@android:drawable/btn_radio"
android:text="@string/conf_other_function" />
</RadioGroup>
<ListView
android:id="@+id/lv_participant"
style="@style/Normal_List"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@color/listview_bg_color"
android:footerDividersEnabled="false" >
</ListView>
</LinearLayout>