android中的单选和多选按钮的使用
来源:互联网 发布:淘宝主图素材怎么制作 编辑:程序博客网 时间:2024/05/29 13:06
1.布局文件:
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/radioGroup"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radio1" android:text="@string/female"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radio2" android:text="@string/male"/></RadioGroup><CheckBox android:id="@+id/singBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sing"/><CheckBox android:id="@+id/runBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/run"/><CheckBox android:id="@+id/danceBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/dance"/>
2.activity
package com.example.android1;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.LinearLayout;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;public class LinearLayOut extends Activity{private RadioGroup radioGroup;private RadioButton radio1,radio2;private CheckBox runBox,singBox,danceBox;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button=(Button)findViewById(R.id.button);button.setOnClickListener(new MyButtonListener());//绑定监听器radio1=(RadioButton)findViewById(R.id.radio1);radio2=(RadioButton)findViewById(R.id.radio2);radioGroup=(RadioGroup)findViewById(R.id.radioGroup);runBox=(CheckBox)findViewById(R.id.runBox);singBox=(CheckBox)findViewById(R.id.singBox);danceBox=(CheckBox)findViewById(R.id.danceBox);//单选按钮监听器radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId){// TODO Auto-generated method stubif(radio1.getId()==checkedId){System.out.println("女");//Toast.makeText(LinearLayout.class, "选择了女", Toast.LENGTH_SHORT).show();Toast.makeText(LinearLayOut.this, "选择了女", Toast.LENGTH_SHORT).show();}else if(radio2.getId()==checkedId){System.out.println("男");}}});//复选框监听器,每一个checkbox都需要一个runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked){if(isChecked){System.out.println("runBox is selected");}else{System.out.println("runBox is unselected");}}});singBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked){if(isChecked){System.out.println("singBox is selected");}else{System.out.println("singBox is unselected");}}});danceBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked){if(isChecked){System.out.println("danceBox is selected");}else{System.out.println("danceBox is unselected");}}});}class MyButtonListener implements OnClickListener{@Overridepublic void onClick(View v){Intent intent=new Intent();intent.setClass(LinearLayOut.this, TableLayout.class);LinearLayOut.this.startActivity(intent);}}}
- android中的单选和多选按钮的使用
- Android单选和多选按钮的使用
- Android 单选按钮RadioButton的使用
- android 单选按钮组的使用
- Android 单选按钮RadioButton的使用
- android单选按钮使用
- Android中的 单选按钮和复选框
- Android的单选按钮
- 单选按钮的使用
- 单选按钮的使用
- 【Android】Android单选按钮控件的使用
- 单选按钮和多选按钮的样式设置
- Android开发之单选按钮的使用
- 从零开始学android<RadioButton单选按钮的使用.七.>
- Android开发之单选按钮的使用
- 2.2 复选框和单选按钮的使用实例
- Android:单选按钮
- 自动链接、自动完成输入框、开关按钮和单选、多选按钮的简单使用
- Pig加载配置的四种方式
- 面试准备
- sql 语句的limit的用法
- 微软等面试100题筛选答案-25-求最长连续数字子串
- 利用window自带防火墙限制ip访问。
- android中的单选和多选按钮的使用
- 回归测试——游戏版本发布前的最后关口
- wap开发
- gdb教程
- Java优先队列(PriorityQueue)示例
- [Ljava.lang.String; cannot be cast to java.lang.String错误 [转]
- OSG 模型添加(含自己画的模型,已有模型),对添加的模型做平移 缩放等。
- mysql insert if not exists防止插入重复记录的方法
- Hibernate模板的使用问题