android RadioGroup 初始化注意事项

时间:2022-10-03 19:47:06
//正确的设置流程
private
RadioGroup mDualMode = (RadioGroup)findViewById(R.id.dualmode);
if(type != null && type.equals("RUIM")){

Log.i(TAG,
"________________________________________CDMA RUIM");
mDualMode.check(R.id.dualmode_2);
}
else{
Log.i(TAG,
"________________________________________GSM SIM");
mDualMode.check(R.id.dualmode_1);
}
mDualMode.setOnCheckedChangeListener(
this);

 

//错误的设置流程
private RadioGroup mDualMode = (RadioGroup)findViewById(R.id.dualmode);

mDualMode.setOnCheckedChangeListener(
this);

if(type != null && type.equals("RUIM")){

Log.i(TAG,
"________________________________________CDMA RUIM");
mDualMode.check(R.id.dualmode_2);
}
else{
Log.i(TAG,
"________________________________________GSM SIM");
mDualMode.check(R.id.dualmode_1);
}

 

总结:当设置事件setOnCheckedChangeListener写在设置check的前会导致初始化混乱。