Android简单的用户信息注册界面
来源:互联网 发布:淘宝上日本代购哪家好 编辑:程序博客网 时间:2024/06/05 05:15
一、运行测试效果
二、基本组件和原理
1、基本组件:AndroidUI、View、TextView、EditText、Button、RadioGroup、ViewSwitcher、动画AnimationDrawable、Animation、事件监听器OnClickListener、线程Thread及Handler刷新界面等。
2、原理:输入用户名、密码、邮箱、昵称可以点击旁边的button来判断可用性(程序中假设均可用,显示正确符号),在用户输入的所有信息都不为空时,点击button执行注册验证,启动动画,在新线程中模拟从远程验证用户信息的方法(程序中sleep(2000)假设验证失败),刷新界面组件。
三、我的理解和思考全在代码中...
package com.ui;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.RadioGroup;import android.widget.Toast;import android.widget.ViewSwitcher;import com.example.appmainui.R;import com.widget.BaseActivity;/** * @name 用户注册页面 * @descripation 输入用户信息,验证信息正确性,信息入库 * @author 樊俊彬 * @date 2014-6-9 * @version 1.0 */public class RegistryUserInfoActivity extends BaseActivity {private EditText registInputUserName;private EditText registInputPassword;private EditText registInputEmail;private EditText registInputNickName;private RadioGroup registInputSex;private EditText registInputAge;private EditText registInputPhone;private Button registButtonCheckUserName;private Button registButtonCheckPassword;private Button registButtonCheckEmail;private Button registButtonCheckNickName;private Button registButtonRegister;private ViewSwitcher registViewSwitcher;private View registView;private AnimationDrawable registAnimation;private boolean isRegistSuccess = false;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.regist_user_info);initUI();}/** * 初始化界面组件 */private void initUI() {// 用户输入的信息registInputUserName = (EditText) findViewById(R.id.registInputUserName);registInputPassword = (EditText) findViewById(R.id.registInputPassword);registInputEmail = (EditText) findViewById(R.id.registInputEmail);registInputNickName = (EditText) findViewById(R.id.registInputNickName);registInputSex = (RadioGroup) findViewById(R.id.registInputSex);registInputAge = (EditText) findViewById(R.id.registInputAge);registInputPhone = (EditText) findViewById(R.id.registInputPhone);registViewSwitcher = (ViewSwitcher) findViewById(R.id.registViewSwitcher);registView = (View) findViewById(R.id.registViewLoading);// 检测用户名可用性按钮registButtonCheckUserName = (Button) findViewById(R.id.registButtonCheckUserName);registButtonCheckUserName.setOnClickListener(checkAvailabilityListener(registButtonCheckUserName, registInputUserName));// 检测密码可用性按钮registButtonCheckPassword = (Button) findViewById(R.id.registButtonCheckPassword);registButtonCheckPassword.setOnClickListener(checkAvailabilityListener(registButtonCheckPassword, registInputPassword));// 检测Email可用性registButtonCheckEmail = (Button) findViewById(R.id.registButtonCheckEmail);registButtonCheckEmail.setOnClickListener(checkAvailabilityListener(registButtonCheckEmail, registInputEmail));// 检测昵称可用性registButtonCheckNickName = (Button) findViewById(R.id.registButtonCheckNickName);registButtonCheckNickName.setOnClickListener(checkAvailabilityListener(registButtonCheckNickName, registInputNickName));// 注册用户信息registButtonRegister = (Button) findViewById(R.id.registButtonRegister);registButtonRegister.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {String inputUserName = registInputUserName.getText().toString();String inputPassword = registInputPassword.getText().toString();String inputEmail = registInputEmail.getText().toString();String inputNickName = registInputNickName.getText().toString();String inputSex = "";String inputAge = registInputAge.getText().toString();String inputPhone = registInputPhone.getText().toString();// 开启动画,执行注册验证registAnimation = (AnimationDrawable) registView.getBackground();registAnimation.start();registViewSwitcher.showNext();registUserInfo(inputUserName, inputPassword, inputEmail, inputNickName, inputSex, inputAge, inputPhone);}});}/** * 检测可用性按钮事件监听器 * * @param button * @param editText * @return */public View.OnClickListener checkAvailabilityListener(final Button button,final EditText editText) {return new OnClickListener() {@Overridepublic void onClick(View arg0) {// 输入不能为空if (editText.getText().toString().equals("")) {button.setBackgroundResource(R.drawable.icon_cool_false);} else {button.setBackgroundResource(R.drawable.icon_cool_true);}}};}/** * 启动新线程,注册验证用户输入的信息 * * @param inputUserName * @param inputPassword * @param Email * @param NickName * @param Sex * @param Age * @param Phone */protected void registUserInfo(String inputUserName, String inputPassword,String inputEmail, String inputNickName, String inputSex, String inputAge, String inputPhone) {// 刷新界面final Handler handler = new Handler() {public void handleMessage(Message msg) {// 注册成功if (msg.what == 1) {Toast.makeText(RegistryUserInfoActivity.this, "注册成功",Toast.LENGTH_SHORT).show();finish();}// 注册失败if (msg.what == 0) {Toast.makeText(RegistryUserInfoActivity.this, "注册失败",Toast.LENGTH_SHORT).show();registViewSwitcher.showPrevious();}}};// 登陆验证线程new Thread() {@Overridepublic void run() {super.run();Message msg = new Message();try {// 验证输入的信息sleep(2000);isRegistSuccess = false;if (isRegistSuccess) {// 验证成功msg.what = 1;} else {// 验证失败msg.what = 0;}} catch (InterruptedException e) {e.printStackTrace();msg.what = -1;msg.obj = e;}handler.sendMessage(msg);}}.start();}}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="50dip" android:background="@drawable/head_bg_registry" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="用户注册" android:textColor="@color/white" android:textSize="@dimen/text_size_23" /> </RelativeLayout> <!-- 信息输入框 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="10.0dip" android:layout_marginRight="10.0dip" android:layout_marginTop="20.0dip" android:background="@drawable/shape_bg_regist_user_info" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:gravity="center_vertical" android:orientation="horizontal" > <TextView style="@style/regist_user_info_text_view" android:text="用户名:" /> <EditText android:id="@+id/registInputUserName" style="@style/regist_user_info_input" android:hint="字母/数字/符号的任意组合" /> <Button android:id="@+id/registButtonCheckUserName" android:layout_width="20dip" android:layout_height="20dip" android:layout_marginRight="10dip" android:background="@drawable/icon_cool_check" /> </LinearLayout> <View style="@style/regist_user_info_cutline_view" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:gravity="center_vertical" android:orientation="horizontal" > <TextView style="@style/regist_user_info_text_view" android:text="密 码:" /> <EditText android:id="@+id/registInputPassword" style="@style/regist_user_info_input" android:hint="密码长度不超过16位" android:password="true" /> <Button android:id="@+id/registButtonCheckPassword" android:layout_width="20dip" android:layout_height="20dip" android:layout_marginRight="10dip" android:background="@drawable/icon_cool_check" /> </LinearLayout> <View style="@style/regist_user_info_cutline_view" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:gravity="center_vertical" android:orientation="horizontal" > <TextView style="@style/regist_user_info_text_view" android:text="邮箱号:" /> <EditText android:id="@+id/registInputEmail" style="@style/regist_user_info_input" android:hint="也可作登陆用户名使用" /> <Button android:id="@+id/registButtonCheckEmail" android:layout_width="20dip" android:layout_height="20dip" android:layout_marginRight="10dip" android:background="@drawable/icon_cool_check" /> </LinearLayout> <View style="@style/regist_user_info_cutline_view" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:gravity="center_vertical" android:orientation="horizontal" > <TextView style="@style/regist_user_info_text_view" android:text="昵 称:" /> <EditText android:id="@+id/registInputNickName" style="@style/regist_user_info_input" android:hint="个性点的好" /> <Button android:id="@+id/registButtonCheckNickName" android:layout_width="20dip" android:layout_height="20dip" android:layout_marginRight="10dip" android:background="@drawable/icon_cool_check" /> </LinearLayout> <View style="@style/regist_user_info_cutline_view" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:gravity="center_vertical" android:orientation="horizontal" > <TextView style="@style/regist_user_info_text_view" android:text="性 别:" /> <RadioGroup android:id="@+id/registInputSex" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_marginLeft="10.0dip" android:layout_marginRight="15.0dip" android:background="@android:color/white" android:orientation="horizontal" > <RadioButton android:id="@+id/reg_boy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="帅男" android:textColor="@android:color/black" android:textSize="18.0sp" /> <RadioButton android:id="@+id/reg_girl" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="60.0dip" android:checked="false" android:text="美女" android:textColor="@android:color/black" android:textSize="18.0sp" /> </RadioGroup> </LinearLayout> <View style="@style/regist_user_info_cutline_view" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:gravity="center_vertical" android:orientation="horizontal" > <TextView style="@style/regist_user_info_text_view" android:text="年 龄:" /> <EditText android:id="@+id/registInputAge" style="@style/regist_user_info_input" android:hint="点击输入数字" android:phoneNumber="true" /> </LinearLayout> <View style="@style/regist_user_info_cutline_view" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:gravity="center_vertical" android:orientation="horizontal" > <TextView style="@style/regist_user_info_text_view" android:text="手机号:" /> <EditText android:id="@+id/registInputPhone" style="@style/regist_user_info_input" android:hint="方便与您联系" android:phoneNumber="true" /> </LinearLayout> <View style="@style/regist_user_info_cutline_view" /> </LinearLayout> <!-- 提示文本 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="20.0dip" android:layout_marginRight="20.0dip" android:layout_marginTop="10.0dip" android:gravity="left" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/register_tip" android:textColor="@color/black" android:textSize="@dimen/text_size_12" /> </LinearLayout> <ViewSwitcher android:id="@+id/registViewSwitcher" android:layout_width="fill_parent" android:layout_height="wrap_content" > <!-- 注册按钮 --> <Button android:id="@+id/registButtonRegister" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="30.0dip" android:layout_marginRight="30.0dip" android:layout_marginTop="20.0dip" android:background="@drawable/btn_bg_regist_user_info" android:text="注 册" android:textColor="#ff000000" android:textSize="@dimen/text_size_21" /> <View android:id="@+id/registViewLoading" android:layout_width="120.0dip" android:layout_height="120.0dip" android:layout_gravity="center" android:background="@anim/login_loading" /> </ViewSwitcher></LinearLayout>
1 0
- Android简单的用户信息注册界面
- Android注册界面之Md5对用户信息加密
- 简单的注册界面
- 简单的注册信息界面
- android 之登录注册用户信息
- 【Android】用户登录注册界面开发及用户信息管理案例代码详解
- 【Android】用户登录注册界面开发及用户信息管理案例代码详解
- Android用户登录注册界面开发及用户信息管理案例代码详解
- 【Android】用户登录注册界面开发及用户信息管理案例代码详解
- android 简易的注册界面
- 【代码生成Android布局】例.用户信息界面的生成
- (HTML)简单的用户注册界面
- 简单的注册界面及相关判断
- 一个简单的Jsp注册界面
- 一个简单的php注册界面
- jsp实现了简单的注册界面
- JSP实现简单的注册界面
- 类似于QQ用户信息的界面
- github常见操作和常见错误!错误提示:fatal: remote origin already exists.
- lua 中pairs 和 ipairs区别
- 网易游戏面试题——打怪按概率掉装备
- 给VS添加VASSISTX插件后汉字下出现红色下划线
- Swift学习1——基本语法介绍
- Android简单的用户信息注册界面
- C++ Primer 笔记一(类型、常量)
- WinRAR v5.10 正式版
- 调试细节 !!! 很重要奥!
- weka[3] - J48(二)
- android cmd adb命令安装和删除apk应用
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第一次实验:NPC,回溯,八皇后问题
- WEB程序会话管理--HttpSession和Cookie