一简介:

RadioGroup作为一个单选按钮组,可以设置为性别选择男或则女,地址选择等等,作为一个android入门级选手,就简单的说一下RadioGroup组中RadioButton的布局和初始化操作,以及禁用整个RadioGroup。

二具体介绍:

布局:

  <RadioGroup                        android:id="@+id/rg_Orientation"                        android:layout_width="match_parent"                        android:layout_height="wrap_content"                        android:layout_marginLeft="10dp"                        android:layout_marginTop="10dp">                        <RadioButton                            android:id="@+id/rb_Portrait"                            android:layout_width="wrap_content"                            android:layout_height="wrap_content"                            android:checked="true"                            android:drawableRight="@drawable/r_portrait" />                        <RadioButton                            android:id="@+id/rb_Landscape"                           android:layout_marginTop="10dp"                            android:layout_width="wrap_content"                            android:layout_height="wrap_content"                            android:drawableRight="@drawable/r_landscape"/>                    RadioGroup>

初始化:

 radioGroup_orientation = (RadioGroup) findViewById(R.id.rg_Orientation);

给初始化完成的RadioGroup设置监听

radioGroup_orientation.setOnCheckedChangeListener(radioGrouplisten);

监听的具体逻辑

//RadioGroup控件的初始化    private RadioGroup.OnCheckedChangeListener radioGrouplisten = new RadioGroup.OnCheckedChangeListener() {        @Override        public void onCheckedChanged(RadioGroup group, int checkedId) {            int id = group.getCheckedRadioButtonId();            switch (group.getCheckedRadioButtonId()) {                case R.id.rb_Landscape:                    orientation = Orientation.landscape;                    Log.i("orientation",orientation.toString());                    //Toast.makeText(PrintSettingActivity.this, orientation.toString(), Toast.LENGTH_SHORT).show();                    break;                case R.id.rb_Portrait:                    orientation = Orientation.Portrait;                    Log.i("orientation",orientation.toString());                    //Toast.makeText(PrintSettingActivity.this, orientation.toString(), Toast.LENGTH_SHORT).show();                    break;                default:                    break;            }        }    };

RadioGroup的所有单选按钮均不可点击,需要遍历RadioGroup中的每一个单选按钮,可以根据限定条件来对按钮进行控制

 public void disableRadioGroup(RadioGroup radioGroup,String fileName){        if(recPath.endsWith("pdf")){            for (int i = 0; i < radioGroup.getChildCount(); i++) {                radioGroup.getChildAt(i).setEnabled(false);            }        }    }

三总结:

  

  

 

转载于:https://www.cnblogs.com/mlgm/p/9673277.html

更多相关文章

  1. 【Android】监听蓝牙状态变化
  2. Android的几种按钮控件: Options Menu / Context Menu / Panel Me
  3. Android仿淘宝头条垂直滚动,垂直走马灯,公告
  4. 小白用网格布局实现简单的计算器 ——Android
  5. Android用yasea集成推流服务并实现美颜滤镜
  6. 【Android开发 蓝牙连接状态】Android实时检测蓝牙连接状态
  7. Android(安卓)SwipeLayout实现界面滑动布局
  8. Android(安卓)如何监听返回键,弹出一个退出对话框
  9. Android(安卓)应用导入第三方jar包

随机推荐

  1. 如何修改三方构件的布局
  2. 走心的Android(安卓)10 适配指南,手把手上
  3. Android(安卓)4.0 与 android2.3 差异
  4. Android(安卓)联系人 数据库解析
  5. Android中获取TextView一行最多能显示几
  6. Android(安卓)P: U盘挂载过程简述
  7. Activity生命周期和对话框
  8. 《第一行代码》阅读笔记(三十四)——Materi
  9. Android(安卓)通过Intent简单实现分享功
  10. opengl fbo 离屏渲染