WEB开发网
开发学院手机开发Android 开发 Android控件(View)之TextView, Button, ImageButt... 阅读

Android控件(View)之TextView, Button, ImageButton, ImageView, CheckBox

 2010-09-27 02:07:00 来源:WEB开发网   
核心提示:< /LinearLayout>_CheckBox.java代码package com.webabcd.view;import android.app.Activity;import android.os.Bundle;import android.widget.CheckBox;import androi

< /LinearLayout>

_CheckBox.java

代码

package com.webabcd.view;

import android.app.Activity;

import android.os.Bundle;

import android.widget.CheckBox;

import android.widget.CompoundButton;

import android.widget.TextView;

public class _CheckBox extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

this.setContentView(R.layout.checkbox);

setTitle("CheckBox");

CheckBox chk = (CheckBox) this.findViewById(R.id.chk1);

// setOnCheckedChangeListener() - 响应复选框的选中状态改变事件

chk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

TextView txt = (TextView) _CheckBox.this.findViewById(R.id.textView);

txt.setText("CheckBox01 的选中状态:" + String.valueOf(isChecked));

}

});

}

}

6、RadioButton 的 Demo

radiobutton.xml

代码

< ?xml version="1.0" encoding="utf-8"?>

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent">

< TextView android:layout_width="fill_parent"

android:layout_height="wrap_content" android:id="@+id/textView" />

< !--

RadioButton - 单选框控件

RadioGroup - 对其内的单选框控件做分组

checkedButton - 指定组内被选中的单选框的 ID

-->

< RadioGroup android:id="@+id/radioGroup"

android:layout_width="fill_parent" android:layout_height="fill_parent"

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Android 控件 View

编辑录入:coldstar [复制链接] [打 印]
赞助商链接