展会信息港展会大全

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

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

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

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

main.xml代码:

01

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

02

android:text="我是BOX1"

03

android:layout_width="fill_parent"

04

android:layout_height="wrap_content"

05

/>

06

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

07

android:text="我是BOX2"

08

android:layout_width="fill_parent"

09

android:layout_height="wrap_content"

10

/>

11

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

12

android:layout_width="wrap_content"

13

android:layout_height="wrap_content"

14

android:text="按我"

15

/>

主程序代码:

01

package com.pocketdigi;

02

03

import android.app.Activity;

04

import android.os.Bundle;

05

import android.view.View;

06

import android.view.View.OnClickListener;

07

import android.widget.Button;

08

import android.widget.CheckBox;

09

10

public class main extends Activity {

11

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

12

@Override

13

public void onCreate(Bundle savedInstanceState) {

14

super.onCreate(savedInstanceState);

15

setContentView(R.layout.main);

16

17

boxDemo();

18

19

}

20

CheckBox box1;

21

CheckBox box2;

22

private void boxDemo(){

23

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

24

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

25

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

26

b1.setOnClickListener(Dialog);

27

}

28

private Button.OnClickListener Dialog=new OnClickListener(){

29

30

@Override

31

public void onClick(View v) {

32

// TODO Auto-generated method stub

33

String s="";

34

if(box1.isChecked()){

35

s+="box1,";

36

}

37

if(box2.isChecked()){

38

s+="box2";

39

}

40

setTitle(s);

41

}

42

43

};

44

}

赞助本站

人工智能实验室

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

AiLab云推荐
推荐内容
展开

热门栏目HotCates

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