展会信息港展会大全

Android UI设计 CheckBox 复选框用法
来源:互联网   发布日期:2015-11-25 22:35:19   浏览:3898次  

导读:CheckBox复选框用法,先看效果图选择点击按钮后,会在标题栏显示选中的项。main.xml代码:CheckBox android:id=@+id/box1android:text=我是BOX1android:layout_width=fill_parentandroid:layout_height=......

CheckBox复选框用法,先看效果图

\

选择点击按钮后,会在标题栏显示选中的项。

main.xml代码:

<CheckBox android:id="@+id/box1"

android:text="我是BOX1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

<CheckBox android:id="@+id/box2"

android:text="我是BOX2"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

<Button android:id="@+id/b1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="按我"

/>

主程序代码:

package com.pocketdigi;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.CheckBox;

public class main extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

boxDemo();

}

CheckBox box1;

CheckBox box2;

private void boxDemo(){

box1=(CheckBox)findViewById(R.id.box1);

box2=(CheckBox)findViewById(R.id.box2);

Button b1=(Button)findViewById(R.id.b1);

b1.setOnClickListener(Dialog);

}

private Button.OnClickListener Dialog=new OnClickListener(){

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

String s="";

if(box1.isChecked()){

s+="box1,";

}

if(box2.isChecked()){

s+="box2";

}

setTitle(s);

}

};

}

赞助本站

人工智能实验室

相关热词: 复选框 CheckBox UI设计

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港