radioButton控件的使用方法

radioButton控件的使用方法

radioButton控件的定义

private RadioGroup rg;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.explain);
    rg=(RadioGroup)findViewById(R.id.radio_group); //定义radioGroup控件
    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {//表示RadioGroup中的radioButton状态切换时触发的监听
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
            RadioButton rb = (RadioButton)findViewById(checkedId); //选中radioButton的对象资源id获取radioButton对象
            String str = rb.getText().toString();//获取选中radioButton的文本
            Toast.makeText(Explain.this,"Hello"+str,Toast.LENGTH_SHORT).show();            			  
        }
     });
}

将radioButton圆点去除

    

布局xml




    

        

        

        
        
    



你可能感兴趣的:(Android开发)