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;

                }
         }
    }
  • 相关阅读:
    python 查看源代码
    团队项目5-冲刺合集
    系统设计(团队作业4)
    《次元唤醒 需求规格说明书v1.0》
    团队选题报告
    来自异次元的一篇博客
    《口算大作战 概念版》功能规格说明书
    我不会优化啊!!!
    Python装饰器实现异步回调
    Python杀死windows进程
  • 原文地址:https://www.cnblogs.com/windwithlife/p/1529619.html
Copyright © 2011-2022 走看看