多选一机制的实现(RadioButton的实现)

*--------------------------------------------------------------------------
public class Helloworld extends Activity implements android.widget.RadioGroup.OnCheckedChangeListener{
//省略部分代码
private RadioGroup rg;
rg.setOnCheckedChangeListener(this);
     //通过实现接口来实现监听
public void onCheckedChanged(RadioGroup group, int checkedId) {
  // TODO Auto-generated method stub
  //checkedId 就是被选中的button的ID
  switch (checkedId) {
  case R.id.radio0:
   Toast.makeText(Helloworld.this, "男男男", 1).show();
   break;
  case R.id.radio1:
   Toast.makeText(Helloworld.this, "女女女", 1).show();
   break;
  default:
   break;
  }
 }
*--------------------------------------------------------------------------

你可能感兴趣的:(android)