android 的常用控件
来源:互联网 发布:超级基因优化液压缩 编辑:程序博客网 时间:2024/05/18 02:15
本实例实现了单项选择,多项选择,单项选择按钮必须包括在RadionGroup
--------------AndroidwidgetActivity------------
import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;public class AndroidwidgetActivity extends Activity {/** Called when the activity is first created. */private RadioGroup radioSex;private RadioButton femaleButton;private RadioButton maleButton;private CheckBox redCheck;private CheckBox blueCheck;public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main); //得到main.xml中的控件radioSex = (RadioGroup) findViewById(R.id.sex);femaleButton = (RadioButton) findViewById(R.id.female);maleButton = (RadioButton) findViewById(R.id.male);redCheck = (CheckBox) findViewById(R.id.red);blueCheck = (CheckBox) findViewById(R.id.blue); //给RadioGroup添加监听器radioSex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {public void onCheckedChanged(RadioGroup group, int checkedId) {if (checkedId == femaleButton.getId()) {DisplayToast("你选择的是" + femaleButton.getText());} else {DisplayToast("你选择的是" + maleButton.getText());}}}); //给CheckBox添加控件redCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {if (redCheck.isChecked()) {DisplayToast("你选择的是" + redCheck.getText());}}});blueCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {if (blueCheck.isChecked()) {DisplayToast("你选择的是" + blueCheck.getText());}}});}/** * Toast 用法 * * public static Toast makeText (Context context, int resId, int duration) * * context 显示的内容对象 resId 显示的字符串的id duration 显示的时间长度. LENGTH_SHORT 或 * LENGTH_LONG * */public void DisplayToast(String str) {// 显示ToastToast toast = Toast.makeText(this, str, Toast.LENGTH_LONG);// 设置Toast显示的位置toast.setGravity(Gravity.TOP, 0, 220);toast.show();}}-------------main.xml----------
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RadioGroup android:id="@+id/sex" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RadioButton android:id="@+id/female" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Female" /> <RadioButton android:id="@+id/male" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Male" /> </RadioGroup> <CheckBox android:id="@+id/red" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="红色" /> <CheckBox android:id="@+id/blue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="蓝色" /></LinearLayout>
- android 的常用控件
- Android 常用的控件
- Android常用控件的信息!
- Android当中的常用控件
- android的常用控件总结
- Android 常用控件的信息
- android中常用的控件
- Android中常用的控件
- 【Android】Android常用控件的基本使用
- android常用的控件ViewPager的使用
- Android的ListView控件的常用适配器
- android中常用的一些控件
- Android常用控件的基本使用说明
- android:cha1.3 常用控件的设置
- Android中常用的UI控件
- android之 控件常用的属性
- [android]控件TextView的常用属性
- [android]控件ImageView的常用属性
- 局域网组成部分和工作模式
- ibbackup参考手册
- SMB研究心得(Redhat linux 9.0)
- C#构造函数和析构函数
- sql server事务日志文件的收缩处理
- android 的常用控件
- MySQL:MySQL 存储过程参数用法 in, out, inout
- java学习步骤
- poj 2237(Catenyms)
- Java不太注意的陷阱
- 实现左右屏切换
- JAVA [ 多线程 ]
- redhat linux 9.0 VSFTP配置大全
- poj 2455(二分加网络流(dinic))