Android开发记录三之单选、多选按钮及进度条
2014-07-07 23:11
393 查看
1.单选按钮
布局文件设置:
布局文件如下:
3.Toast的使用
visibility是可视性,gone是用程序启动才开始,visible是可视,invisible是不可视
java代码用法:
布局文件设置:
<?xml version="1.0" encoding ="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RadioGroup android:id="@+id/rg" android:layout_width="fill_parent" android:layout_height="wrap_content" > <RadioButton android:id="@+id/rb1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/male" /> <RadioButton android:id="@+id/rb2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/female" /> </RadioGroup> </LinearLayout>java代码实现如下:
rg = (RadioGroup) this.findViewById(R.id.rg); rb1 = (RadioButton) this.findViewById(R.id.rb1); rb2 = (RadioButton) this.findViewById(R.id.rb2); rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if (rb1.getId() == checkedId) { Toast.makeText(MainActivity.this, "male", Toast.LENGTH_SHORT).show(); } else if (rb2.getId() == checkedId) { Toast.makeText(MainActivity.this, "female", Toast.LENGTH_SHORT).show(); } } });2.多选按钮
布局文件如下:
<CheckBox android:id="@+id/a" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/aa" /> <CheckBox android:id="@+id/b" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/bb" /> <CheckBox android:id="@+id/c" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/cc" />
cb1 = (CheckBox) this.findViewById(R.id.a); cb2 = (CheckBox) this.findViewById(R.id.b); cb3 = (CheckBox) this.findViewById(R.id.c); cb1.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked) { Toast.makeText(MainActivity.this, R.string.aa, Toast.LENGTH_SHORT).show(); } } }); cb2.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked) { Toast.makeText(MainActivity.this, R.string.bb, Toast.LENGTH_SHORT).show(); } } }); cb3.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked) { <pre name="code" class="java"><span style="white-space:pre"> </span>Toast.makeText(MainActivity.this, R.string.cc,Toast.LENGTH_SHORT).show();
3.Toast的使用
Toast.makeText(MainActivity.this, R.string.cc,Toast.LENGTH_SHORT).show(); //参数分别为类名,字符串值,常量值4.ProgressBar
visibility是可视性,gone是用程序启动才开始,visible是可视,invisible是不可视
<ProgressBar android:id="@+id/pb" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:visibility="visible" /> <Button android:id="@+id/bt" android:layout_width="fill_parent" android:layout_height="wrap_content" />
java代码用法:
<span style="white-space:pre"> </span>pb=(ProgressBar)this.findViewById(R.id.pb); bt=(Button)this.findViewById(R.id.bt); bt.setOnClickListener(new OnClickListener() { public void onClick(View v) {//匿名内部类 // TODO Auto-generated method stub if(i==0){ pb.setVisibility(View.VISIBLE); //设置为可见状态 }else if (i<100){ pb.setProgress(i); pb.setSecondaryProgress(i+10);//设置第二进度条 }else{ pb.setProgress(100); } i+=10;//i为全局变量 } });
相关文章推荐
- android控件开发之Radio(单选按钮)和CheckBox(多选按钮)开发
- Android开发,带单选按钮和多选按钮的对话框
- android-----相对布局+单选按钮+多选按钮
- 多选按钮(作业)--MarsChen Android 开发教程笔记
- Android单选和多选按钮的使用
- Android开发之单选按钮的使用
- 多选按钮(CheckBox)——Mars Android开发视频教程之第一季第九集(重)
- Android 几行代码实现 单选/多选 按钮组
- Android项目开发经验小结----ListView的单选模式和多选模式
- Android开发之单选按钮的使用
- Android开发技巧——自定义单选或多选的ListView
- android开发小技巧(4)漂亮的单选按钮(非radiobutton)
- 【Android 开发】:UI控件之单选按钮 RadioButton 的使用方法
- 单选按钮(作业)--MarsChen Android 开发教程学习笔记
- iOS开发系列之常用自定义控件开发集—自定义单选按钮或者多选按钮控件开发
- Android开发技巧——自定义单选或多选的ListView
- 单选按钮(RadioButton)——Mars Android开发视频教程之第一季第十集(重)
- 【Android开发】基本组件-单选按钮
- Android -- 对话框 Dialog: 确定取消,单选多选,进度显示, 常用控件示例:单选多选框,下拉列表,进度条,自动完成文本框, 菜单显示
- android中的单选和多选按钮的使用