• Android (界面编程#4RadioButton)


          Android中RadioButton的使用同其它语言中的RadioButton使用相似。
          在Android中,RadioButton同其它继承于View的界面元素一样,可单独使用,OnClickListener,当然最常用的方式是以组合方使用,组合方式使用时,要使用RadioGroup类,这个类同时也是一个布局类(layout),可以使用布局参数(LayoutParams)对象来放置其中的RadioButton相对位置。
    一,单独使用RadiosButton
          在Activity类中可以如此使用。
           RadioButton  rbtn = new RadioButton(this);
           rbtn.setOnClickListener( new OnClickListener(){public void onClick(View v){setTitle("test!")}});
    二, 组合使用
     public class Test extends Activity implements OnCheckedChangeListener
    {
          private RadioGroup mgroup = null;
          @Override public void onCreate(Bundle icicle)
         {
                super.onCreate(icicle);
                mgroup = new RadioGroup(this);
                mgroup.setOrientation(RadioGroup.VERTICAL);
                mgroup.setOnCheckedChangeListener(this);
                RadioButton btn1 = new RadioButton(this);
                btn1.setId(100);
                mgroup.addView(btn1);
                RadioButton btn2 = new RadioButton(this);
                btn2.setId(101);
                mgroup.addView(btn2);
                mgroup.setOnCheckedChangeListener(this);
          }
         public void onCheckedChanged(RadioGroup arg0, int arg1)
         {
                 switch(arg0.getCheckedRadioButtonId())
                {
                 case 100:
                        setTitle("you cliecked RadioButton 1"); break;
                 case 101:
                        setTitle("you cliecked RadioButton 2"); break;
                 default:
                        break;

                }
         }
    }
  • 相关阅读:
    Quartz定时调度CronTrigger时间配置格式说明与实例
    JAVA中堆和栈的区别
    s:iterator循环输出数字
    JAVA 遍历文件夹下的所有文件(递归调用和非递归调用)
    FilenameFilter总结
    Oracle sql"NOT IN"语句优化,查询A表有、B表没有的数据
    Java并发教程(Oracle官方资料)
    做考试系统用到的关于onbeforeunload一些兼容性问题
    Java集合类ArrayList循环中删除特定元素
    Log4j写入数据库详解
  • 原文地址:https://www.cnblogs.com/windwithlife/p/1529619.html
Copyright © 2020-2023  润新知