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) {
    
    }
    
    }
    

      

  • 相关阅读:
    Windows系统批处理命令实现计划关机
    Git如何将本地test分支设置跟踪origin/test分支
    JavaScript动态实现div窗口弹出&消失功能
    深入理解 Array.prototype.map()
    JS中集合对象(Array、Map、Set)及类数组对象的使用与对比
    Vue的移动端多图上传插件vue-easy-uploader
    如何开发一个npm包并发布
    emlog编辑器探寻之旅
    linux下安装nginx
    原生JavaScript中动画与特效的实现原理
  • 原文地址:https://www.cnblogs.com/meetweb/p/2844356.html
Copyright © 2011-2022 走看看