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 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"
更多精彩
赞助商链接