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;

                }
         }
    }
  • 相关阅读:
    Shell 基础
    史上最全储能系统优缺点梳理
    IEEE文章分类
    【能源常识】如何理解“电力电量平衡”
    最优化基础(五)
    最优化基础(四)
    json
    python基础知识之zip
    Python sendmail
    指定的结尾换行
  • 原文地址:https://www.cnblogs.com/windwithlife/p/1529619.html
Copyright © 2011-2022 走看看