08- android CheckBox 复选框
目标:掌握CheckBox多选框的使用;
在android 中如果想使用复选框,可以使用android.widget.CheckBox类完成
java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.widget.TextView | ||||
↳ | android.widget.Button | ||||
↳ | android.widget.CompoundButton | ||||
↳ | android.widget.CheckBox |
复选框可以直接使用CheckBox实现:
(eclipse 提示信息区分大小写)
例如:
<?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" >
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="您经常浏览的网站" />
<CheckBox
android:id="@+id/url1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="www.baidu.com" /> //默认显示内容
<CheckBox
android:id="@+id/url2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="www.google.com" />
<CheckBox
android:id="@+id/url3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="www.iteye.com" />
<CheckBox ---->通过Activity类实现
android:id="@+id/url4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Activity类
package com.sun.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
public class HelloWorld extends Activity {
private CheckBox box=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//声明周期方法
super.setContentView(R.layout.main);//设置要使用的布局管理器
this.box=(CheckBox)super.findViewById(R.id.url4);//取得组建
this.box.setChecked(true);
this.box.setText("www.hao123.com");//设置显示文字
}
}
更多相关文章
- android文件管理器--文件操作
- android 写布局的时候注意大小写
- Android下文件资源管理器雏形实现
- android 下载管理器
- Android调用系统自带的文件管理器进行文件选择
- Android当前任务管理器不显示应用进程
- Android相对布局管理器RelativeLayout