Android学习笔记04
来源:互联网 发布:chocobank网络剧 编辑:程序博客网 时间:2024/06/06 08:35
[Android开发视频教学].01_12_Android常见控件(二)
主要学习
RadioGroup
RadioButton
CheckBox
Toast的用法
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/gender" tools:context=".RadioMain" android:layout_margin="10dp"/> <RadioGroup android:id="@+id/gendergroup" android:layout_width="fill_parent" android:layout_height="wrap_content" > <RadioButton android:id="@+id/male" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/male" /> <RadioButton android:id="@+id/female" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/female" /> </RadioGroup> <CheckBox android:id="@+id/up" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/up" /> <CheckBox android:id="@+id/down" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/down" /> <CheckBox android:id="@+id/left" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/left" /> <CheckBox android:id="@+id/right" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/right" /></LinearLayout>
<resources> <string name="app_name">Android07</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="title_activity_radio_main">RadioMain</string><string name="gender">性别</string><string name="male">男</string><string name="female">女</string><string name="up">上</string><string name="down">下</string><string name="left">左</string><string name="right">右</string></resources>
Java文件
package fegnda.android07;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;public class RadioMain extends Activity {private RadioGroup genderGroup = null;private RadioButton male = null;private RadioButton female = null;private CheckBox up = null;private CheckBox down = null;private CheckBox left = null;private CheckBox right = null;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_radio_main);genderGroup = (RadioGroup) findViewById(R.id.gendergroup);male = (RadioButton) findViewById(R.id.male);female = (RadioButton) findViewById(R.id.female);genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubif (male.getId() == checkedId) {Toast.makeText(RadioMain.this, "男",Toast.LENGTH_SHORT).show();}if (female.getId() == checkedId) {Toast.makeText(RadioMain.this, "女",Toast.LENGTH_SHORT).show();}}});up = (CheckBox) findViewById(R.id.up);down = (CheckBox) findViewById(R.id.down);left = (CheckBox) findViewById(R.id.left);right = (CheckBox) findViewById(R.id.right);up.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {// TODO Auto-generated method stubif (isChecked) {Toast.makeText(RadioMain.this, "上", Toast.LENGTH_SHORT).show();}}});down.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {// TODO Auto-generated method stubif (isChecked){Toast.makeText(RadioMain.this, "下", Toast.LENGTH_SHORT).show();}}});left.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {// TODO Auto-generated method stubif(isChecked){Toast.makeText(RadioMain.this, "左", Toast.LENGTH_SHORT).show();}}});right.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif (isChecked){Toast.makeText(RadioMain.this, "右", Toast.LENGTH_SHORT).show();}}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.activity_radio_main, menu);return true;}}
最终结果
- Android学习笔记04
- Android学习笔记 2011.06.04
- 新手Android学习笔记 04
- Android学习笔记--Gson笔记
- Android学习笔记04_Dialog的建立
- Android学习笔记04_控件
- Android学习笔记04年0918
- Android自定义View学习笔记04
- Android自定义View学习笔记04
- Android框架学习笔记04Volley框架
- Android学习笔记
- Android学习笔记(二)
- android学习笔记--序
- android学习笔记1
- android学习笔记2
- android学习零碎笔记
- Android 学习笔记
- Android学习笔记(一)
- sgu 186 The Chain
- JavaSE第一讲:JavaSE入门、JDK的下载与安装、第一个Java程序、Java程序的编译与执行
- path与classpath区别
- Java中调用js代码
- 智能指针的作用与原理
- Android学习笔记04
- 10月12---10月26号第二周总结
- Python初学感悟
- C语言strlen函数的注意
- 一个游戏程序员的学习资料
- 孙鑫老师VC视频教程笔记1-10课
- 当用new创建对象时(无继承和有继承两种情况下)虚拟机的执行过程
- c#获取当前日期时间
- linux tr命令详解