Android常见控件(二)

Activity07

package org.wp.activity;import android.app.Activity;import android.os.Bundle;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;public class Activity07 extends Activity {private RadioGroup genderGroup;private RadioButton maleButton;private RadioButton femaleButton;private CheckBox swimBox;private CheckBox runBox;private CheckBox readBox;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);genderGroup = (RadioGroup) findViewById(R.id.gender);maleButton = (RadioButton) findViewById(R.id.maleButton);femaleButton = (RadioButton) findViewById(R.id.femaleButton);genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {if (maleButton.getId() == checkedId) {Toast.makeText(Activity07.this, "male",Toast.LENGTH_SHORT).show();} else if (femaleButton.getId() == checkedId) {Toast.makeText(Activity07.this, "female",Toast.LENGTH_SHORT).show();}}});swimBox = (CheckBox) findViewById(R.id.swim);runBox = (CheckBox) findViewById(R.id.run);readBox = (CheckBox) findViewById(R.id.read);swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {if (isChecked) {Toast.makeText(Activity07.this, "swim is checked",Toast.LENGTH_SHORT).show();} else {Toast.makeText(Activity07.this,"swim is unchecked", Toast.LENGTH_SHORT).show();}}});runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {if (isChecked) {Toast.makeText(Activity07.this, "run is checked",Toast.LENGTH_SHORT).show();} else {Toast.makeText(Activity07.this, "run is unchecked",Toast.LENGTH_SHORT).show();}}});readBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {if (isChecked) {Toast.makeText(Activity07.this, "read is checked",Toast.LENGTH_SHORT).show();} else {Toast.makeText(Activity07.this,"read is unchecked", Toast.LENGTH_SHORT).show();}}});}}

main.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:text="@string/hello"    /><RadioGroupandroid:id="@+id/gender"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:id="@+id/maleButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/male"/><RadioButtonandroid:id="@+id/femaleButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/female"/></RadioGroup><CheckBoxandroid:id="@+id/swim"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/swim"/><CheckBoxandroid:id="@+id/run"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/run"/><CheckBoxandroid:id="@+id/read"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/read"/></LinearLayout>

strings.xml

<?xml version="1.0" encoding="utf-8"?><resources><string name="hello">Hello World, Activity07!</string><string name="app_name">Activity07</string><string name="male">男生</string><string name="female">女生</string><string name="swim">游泳</string><string name="run">跑步</string><string name="read">读书</string></resources>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="org.wp.activity" android:versionCode="1" android:versionName="1.0"><application android:icon="@drawable/icon" android:label="@string/app_name"><activity android:name=".Activity07" android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application><uses-sdk android:minSdkVersion="4" /></manifest> 

更多相关文章

  1. Android的GridView控件点击图片变暗效果
  2. Android控件指定方向加边框
  3. Android控件布局属性大全
  4. Android之ListView控件
  5. 系出名门Android(7) - 控件(View)之ZoomControls, Include...
  6. Android在Activity中获得控件宽高和截屏操作
  7. Android常用控件之ExpandableList的使用
  8. android 常见布局及控件的属性详解

随机推荐

  1. android 古怪问题解决集合
  2. Android动态改变TextView字体颜色
  3. android 获取IP
  4. Android圆形进度条
  5. android NinePatchDrawable 9.png图片使
  6. android 怎样用代码设置墙纸
  7. android使用属性动画执行抖动效果
  8. Android:管理应用内存
  9. Internal error. Please refer to https:
  10. 百度地图集成