目标:掌握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");//设置显示文字

}

}

更多相关文章

  1. android文件管理器--文件操作
  2. android 写布局的时候注意大小写
  3. Android下文件资源管理器雏形实现
  4. android 下载管理器
  5. Android调用系统自带的文件管理器进行文件选择
  6. Android当前任务管理器不显示应用进程
  7. Android相对布局管理器RelativeLayout

随机推荐

  1. Android模拟器SD卡的使用
  2. Xposed Android(安卓)hook -方法介绍
  3. Activity and Task(一)
  4. Android(安卓)Build Target no Target av
  5. 沉浸式状态栏,无缝换肤,带3D感觉的侧滑菜单
  6. Mac OS X下搭建Android(安卓)Source编译
  7. ActivityManagerService启动流程详解
  8. Struts2中一流的方式输出
  9. android中使用代码适配屏幕,dp与px互转、s
  10. 使用编译时注解方式实现View注入(Android