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. listview 左滑弹出删除按钮,需要折腾一下
  2. Android(安卓)编程下 Touch 事件的分发和消费机制
  3. Android控件布局属性大全
  4. 第五次Android课堂笔记
  5. Android(安卓)Textview控件
  6. Android(安卓)Dialog 使用 ConstraintLayout 约束布局宽度异常原
  7. Android控件指定方向加边框
  8. Android的GridView控件点击图片变暗效果
  9. Activity从入门到放弃

随机推荐

  1. android 中使用socket使native和framewor
  2. Android消息传递之组件间传递消息
  3. 深入理解Android插件化技术
  4. Android(安卓)IPC之Messenger和AIDL(andr
  5. [转载]Android实现更换皮肤功能
  6. Android中绘制2D图形基础
  7. APK反编译软件以及方法
  8. android之规范命名
  9. 【Android面试知识点系列】Handler相关
  10. 第十二章:Android数据存储(下)