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

      

  • 相关阅读:
    OC与Swift的区别二(常量、变量、运算符)
    OC与Swift的区别一(文件结构)
    OC对象的归档及解档浅析
    OC单例模式的实现
    oc文件基本读写及操作
    IOS之沙盒(Sandbox)机制
    IOS开发之KVC与KVO简述
    SpringMVC控制器配置文件
    spring常用的连接池属性文件配置
    Struts2文件上传方式与上传失败解决方式
  • 原文地址:https://www.cnblogs.com/meetweb/p/2844356.html
Copyright © 2011-2022 走看看