<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:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="50dp"
android:clickable="true"
android:onClick="onclick"
android:text="hello android" /> <ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onclick"
android:src="@drawable/ic_launcher" /> <RadioGroup
android:id="@+id/rg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onclick"
android:orientation="horizontal" > <RadioButton
android:id="@+id/rbMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onclick"
android:text="男" /> <RadioButton
android:id="@+id/rbFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onclick"
android:text="女" /> <CheckBox
android:id="@+id/chkMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:onClick="onclick"
android:text="变男" /> <CheckBox
android:id="@+id/chkFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onclick"
android:text="变女" />
</RadioGroup> </LinearLayout>
package com.sxt.day03_01;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView; public class MainActivity extends Activity {
RadioButton mrbMale,mrbFemale;
RadioGroup mrg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
} private void initView() {
mrbMale=(RadioButton) findViewById(R.id.rbMale);
mrbFemale=(RadioButton) findViewById(R.id.rbFemale);
mrg=(RadioGroup) findViewById(R.id.rg);
setListener();
} private void setListener() {
mrg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.chkMale:
mrbMale.setChecked(true);
break;
case R.id.chkFemale:
mrbFemale.setChecked(true);
break;
}
}
});
} public void onclick(View v){
switch (v.getId()) {
case R.id.tv:
TextView tv=(TextView) v;
Log.i("main", tv.getText().toString());
tv.setTextColor(Color.RED);
break;
case R.id.iv:
ImageView iv=(ImageView) v;
iv.setImageResource(R.drawable.p01);
break;
case R.id.chkMale:
CheckBox chkMale=(CheckBox) v;
mrbMale.setChecked(chkMale.isChecked());
mrbFemale.setChecked(!chkMale.isChecked());
break;
case R.id.chkFemale:
CheckBox chkFemale=(CheckBox) v;
mrbFemale.setChecked(chkFemale.isChecked());
mrbMale.setChecked(!chkFemale.isChecked());
break;
}
}
}

注册:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:columnCount="5"> <TextView
android:text="用 户 名"/>
<EditText
android:id="@+id/etUserName"
android:hint="2-10个字符"
android:layout_columnSpan="4"
android:layout_gravity="fill_horizontal"/>
<TextView
android:text="输入密码"/>
<EditText
android:id="@+id/etPwd"
android:hint="2-10个字符"
android:layout_columnSpan="4"
android:password="true"
android:layout_gravity="fill_horizontal"/>
<TextView
android:text="确认密码"/>
<EditText
android:id="@+id/etFirmPwd"
android:hint="2-10个字符"
android:layout_columnSpan="4"
android:password="true"
android:layout_gravity="fill_horizontal"/>
<TextView
android:layout_marginTop="10dp"
android:text="选择性别"/>
<RadioGroup
android:layout_marginLeft="10dp"
android:layout_columnSpan="4"
android:layout_gravity="fill_horizontal"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbMale"
android:text="男"
android:checked="true"/>
<RadioButton
android:id="@+id/rbFemale"
android:text="女"/>
</RadioGroup>
<TextView
android:text="所在地"/>
<Spinner
android:id="@+id/spinCity"
android:layout_columnSpan="4"
android:entries="@array/citys"/>
<TextView
android:layout_marginTop="10dp"
android:text="选择爱好"/>
<RadioGroup
android:layout_columnSpan="4"
android:orientation="horizontal">
<CheckBox
android:id="@+id/chkReadBook"
android:text="读书"
android:checked="true"/>
<CheckBox
android:id="@+id/chkTour"
android:text="旅游"/>
<CheckBox
android:id="@+id/chkGame"
android:text="电玩"/>
</RadioGroup>
<Button
android:visibility="invisible"/>
<Button
android:id="@+id/btnRegister"
android:onClick="onClick"
android:text="注册"
android:textColor="#fff"
android:padding="3dp"
android:drawableLeft="@drawable/login32x32"
android:background="@drawable/btn_bg"/>
<Button
android:visibility="invisible"/>
<Button
android:id="@+id/btnExit"
android:onClick="onClick"
android:text="退出"
android:textColor="#fff"
android:padding="3dp"
android:drawableLeft="@drawable/exit32x32"
android:background="@drawable/btn_bg"/>
<Button
android:visibility="invisible"/>
</GridLayout>
package com.sxt.day03_02_registerdemo;

import com.sxt.day03_02_registerdemo.entity.User;

import android.os.Bundle;
import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast; public class MainActivity extends Activity {
EditText metUserName,metPwd,metFirmPwd;
RadioButton mrbMale,mrbFemale;
CheckBox mchkReadBook,mchkGame,mchkTour;
Spinner mspinCity; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
} private void initView() {
metFirmPwd=(EditText) findViewById(R.id.etFirmPwd);
metPwd=(EditText) findViewById(R.id.etPwd);
metUserName=(EditText) findViewById(R.id.etUserName); mrbFemale=(RadioButton) findViewById(R.id.rbFemale);
mrbMale=(RadioButton) findViewById(R.id.rbMale); mchkGame=(CheckBox) findViewById(R.id.chkGame);
mchkReadBook=(CheckBox) findViewById(R.id.chkReadBook);
mchkTour=(CheckBox) findViewById(R.id.chkTour); mspinCity=(Spinner) findViewById(R.id.spinCity); } public void onClick(View v){
switch (v.getId()) {
case R.id.btnExit:
finish();//关闭当前的Activity
break;
case R.id.btnRegister:
String name=metUserName.getText().toString();
if(TextUtils.isEmpty(name)){
Toast.makeText(this, "用户名不能为空", 2000).show();
return ;
}
String pwd=metPwd.getText().toString();
if(TextUtils.isEmpty(pwd)){
metPwd.setError("请输出密码");
return ;
}
String firmPwd=metFirmPwd.getText().toString();
if(TextUtils.isEmpty(firmPwd)){
metFirmPwd.setError("确认密码不能为空");
return ;
}
if(!pwd.equals(firmPwd)){
Toast.makeText(this, "确认密码与密码不一致", 2000).show();
return ;
}
char sex;
if(mrbMale.isChecked()){
sex=mrbMale.getText().toString().charAt(0);
}else{
sex=mrbFemale.getText().toString().charAt(0);
}
StringBuilder sb=new StringBuilder();
if(mchkGame.isChecked()){
sb.append(mchkGame.getText().toString());
}
if(mchkReadBook.isChecked()){
sb.append(",").append(mchkReadBook.getText().toString());
}
if(mchkTour.isChecked()){
sb.append(",").append(mchkTour.getText().toString());
}
String city=mspinCity.getSelectedItem().toString();
User user=new User(name, pwd, sex, sb.toString(), city);
Toast.makeText(this, "注册用户:"+user.toString(), 4000).show();
Log.i("main",user.toString());
break;
}
} }
public class User {

    private String name;
private String pwd;
private char sex;
private String hobby;//爱好
private String city; public String getName() {
retu

android 09的更多相关文章

  1. php脚本生成google play url的下载链接,下载apk并自动反编译后获取android版本号

        需求:     get the offer tracking link    follow the redirect to get google play url    Go to http: ...

  2. js生成二维码实例(真实有效)

    js文件  qrcode.js   代码 /*from tccdn minify at 2014-6-4 14:59:43,file:/cn/c/c/qrcode.js*/ /** * @fileov ...

  3. qrcode.js插件将你的内容转换成二维码格式

    ---qrcode.js插件将你的内容转换成二维码格式--- 我之前一直想知道二维码是怎么生成,所以就了解了一下, 最后还是不知道它的原理, 但是,我知道怎么生成. 现在就让我带你制作一个你喜爱的二维 ...

  4. JavaScript二维码生成——qrcode.js

    在开发中,有时候,我们需要根据不同的内容来动态生成二维码,则可以使用qrcode.js这个小插件来实现. 1.qrcode.js文件内容: (1)未压缩(qrcode.js): /** * @file ...

  5. JS生成URL二维码

    需求:项目中需要在UI界面有一个二维码,扫码后可以跳转到二维码包含的URL. 解决方案:在前端用js生成一个包含URL等信息的二维码. 实现: 方案一. <!DOCTYPE HTML PUBLI ...

  6. js将url转换二维码

    二维码生成库 qrcode.js /*from tccdn minify at 2014-6-4 14:59:43,file:/cn/c/c/qrcode.js*/ /** * @fileovervi ...

  7. 纯js生成QRCode

    纯js,不依赖jquery,非常好用,废话不多说,直接上代码! <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  8. vue2.0 引用qrcode.js实现获取改变二维码的样式

    vue代码 <template> <div class="qart"> <div id="qrcode" ref="qr ...

  9. qrCode生成二维码图片

    QRCode.js 是一个用于生成二维码图片的插件. 1.文件脚本 var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,th ...

随机推荐

  1. php函数声明的简单实例

    <?phpecho table(10,5,500);echo table(2,2,400); //函数调用 function table($row,$col,$width){ //通过函数标记t ...

  2. 小爬虫。爬取网站多页的通知标题并存取在txt文档里。

    爬取网页中通知标题的内容展示: this is  1  page!<精算学综合>科目考试参考大纲2016年上半年研究生开题报告评议审核结果公示[答辩]2016下半年研究生论文答辩及学位评定 ...

  3. silverlight中DataGrid数据高亮显示

    效果如图所示, <UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.W ...

  4. 学习Swift -- 协议(下)

    协议(下) 在拓展中添加协议成员 通过扩展使得Dice类型遵循了一个新的协议,这和Dice类型在定义的时候声明为遵循TextRepresentable协议的效果相同.在扩展的时候,协议名称写在类型名之 ...

  5. matlab提速技巧(自matlab帮助文件)

    matlab提速技巧(自matlab帮助文件) 1.首先要学会用profiler.1.1. 打开profiler.To open the Profiler, select View -> Pro ...

  6. iOS内存管理系列之二:自动释放与便捷方法

    有时候一个所有者创建一个对象后,会立刻将该对象的指针传递给其它所有者.这时,这个创建者不希望再拥有这个对象,但如果立刻给它发送一个release消息会导致这个对象被立刻释放掉——这样其它所有者还没有来 ...

  7. c#回调函数写法

    添加一个cs文件,在里面定义回调 using System; using System.Collections.Generic; using System.Linq; using System.Web ...

  8. ‘char *' differs in levels of indirection from 'int'

    这个问题是有与和系统变量重名导致的,如 char* ans = (char*) malloc(10);系统变量是一个int.

  9. Spring MVC 解读——<mvc:annotation-driven/>(转)

    转自:http://my.oschina.net/HeliosFly/blog/205343 Spring MVC 解读——<mvc:annotation-driven/> 一.Annot ...

  10. css li 列表

    ul,li{list-style-type:none;padding:0;margin:0}