Android开发记录三之单选、多选按钮及进度条
来源:互联网 发布:apache johnzon 编辑:程序博客网 时间:2024/05/16 15:48
1.单选按钮
布局文件设置:
<?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 stubif (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() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {// TODO Auto-generated method stubif (isChecked) {Toast.makeText(MainActivity.this, R.string.aa,Toast.LENGTH_SHORT).show();}}});cb2.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {// TODO Auto-generated method stubif (isChecked) {Toast.makeText(MainActivity.this, R.string.bb,Toast.LENGTH_SHORT).show();}}});cb3.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {// TODO Auto-generated method stubif (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 stubif(i==0){pb.setVisibility(View.VISIBLE);//设置为可见状态}else if (i<100){pb.setProgress(i);pb.setSecondaryProgress(i+10);//设置第二进度条}else{pb.setProgress(100);}i+=10;//i为全局变量}});
0 0
- Android开发记录三之单选、多选按钮及进度条
- android控件开发之Radio(单选按钮)和CheckBox(多选按钮)开发
- Android开发之单选按钮的使用
- Android开发之单选按钮的使用
- Android之复选按钮、单选按钮、开关按钮
- 【Android开发】基本组件-单选按钮
- Android 开发 单选按钮的实现
- Android之单选按钮对话框
- Android之单选按钮对话框
- Android入门之单选按钮(RadioButton)
- Android:单选按钮
- iOS开发系列之常用自定义控件开发集—自定义单选按钮或者多选按钮控件开发
- 【Android 开发】:UI控件之单选按钮 RadioButton 的使用方法
- android-----相对布局+单选按钮+多选按钮
- win32之单选按钮
- html之单选按钮
- android单选按钮事件
- Android的单选按钮
- 观察者(Observer)
- csv转成Excel
- CentOS6.5编译部署64位Hadoop2.2.0
- ActionBar
- 在COM组件中调用JavaScript函数
- Android开发记录三之单选、多选按钮及进度条
- 提高你的Python: 解释‘yield’和‘Generators(生成器)’
- hdu 4029 Distinct Sub-matrix ( 后缀数组 + Hash )
- 怎样不使用迅雷而使用浏览器自带的下载进行下载
- URL中汉字编码
- CPU GPU GPGPU【转自firefly_2002】
- eclipse下配置tomcat7的几个重要问题
- missing artifact com.oracle:ojdbc14:jar:10.2.0.2.0解决办法
- Unix环境高级编程阅读笔记(1)