zoukankan      html  css  js  c++  java
  • 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;

                }
         }
    }
  • 相关阅读:
    Flink架构、原理与部署测试
    EntityFramework 简单入个门
    Gdb远程调试Linux内核遇到的Bug
    掌握jQuery插件开发
    两分钟实现安全完备的登录模块
    SQL Server 手把手教你使用profile进行性能监控
    Paxos 实现日志复制同步
    作用域是什么
    Consul 服务注册与服务发现
    C语言之预处理
  • 原文地址:https://www.cnblogs.com/windwithlife/p/1529619.html
Copyright © 2011-2022 走看看