zoukankan      html  css  js  c++  java
  • 安卓学习之--UI控件用法 单选 按钮 下拉框

    1。单选

    .RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只能做出单一选择(单选题).

     <RadioGroup  android:id="@+id/group"
                        android:orientation="horizontal">
                        <RadioButton android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="没过5年"
                            android:checked="true"
                            android:id="@+id/rdyear5"
                            />
                        <RadioButton android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="过5年"
                            android:id="@+id/rdyearno5"
                            />
                    </RadioGroup>
    

      .java

    private RadioGroup group;         
    	private RadioButton rb1 ;  
    	private RadioButton rb2 ;
    private boolean blflag;
    
    group=(RadioGroup) this.findViewById(R.id.group);
    		rb1=(RadioButton) this.findViewById(R.id.rdyear5);
    		rb2=(RadioButton) this.findViewById(R.id.rdyearno5);
    		group.setOnCheckedChangeListener(new checkedlistener());
    
    public class checkedlistener implements RadioGroup.OnCheckedChangeListener{
    
    		@Override
    		public void onCheckedChanged(RadioGroup group, int checkedId) {
    			if(checkedId==R.id.rdyear5){
    				blflag=true;
    			}else if(checkedId==R.id.rdyearno5){
    				blflag=false;
    			}
    		}
    	
    	}
    

      

    按钮 Button是各种UI中最常用的控件之一,它同样也是Android开发中最受欢迎的控件之一,用户可以通过触摸它来触发一系列事件,要知道一个没有点击事件的Button是没有任何意义的,因为使用者的固定思维是见到它就想去点!

    <Button
    android:id="@+id/btncal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="计算" />

    .java

    Button btncal=(Button) this.findViewById(R.id.btncal);  //获取该按钮控件 
    btncal.setOnClickListener(new listener());  //事件
    
    private class listener implements View.OnClickListener{
    
    @Override
    public void onClick(View v) {
    
    }
    
    }
    

      

  • 相关阅读:
    题解:luoguP1861 星之器
    题解:LOJ540游戏
    Yii框架常见问题
    常用ubuntu命令
    Python中的映射数据类型 dict
    Python中的编码问题:ASCII码 Unicoden编码 UTF8编码
    Python中的列表、元组的增、删、改、查
    Python 数据类型之 集合 set
    Python中常见的字符串的操作方法:
    Python程序的控制结构用多分支结构处理身体指标BMI问题
  • 原文地址:https://www.cnblogs.com/meetweb/p/2844356.html
Copyright © 2011-2022 走看看