Android简单的用户信息注册界面
2014-06-11 22:51
1101 查看
一、运行测试效果
二、基本组件和原理
1、基本组件:AndroidUI、View、TextView、EditText、Button、RadioGroup、ViewSwitcher、动画AnimationDrawable、Animation、事件监听器OnClickListener、线程Thread及Handler刷新界面等。
2、原理:输入用户名、密码、邮箱、昵称可以点击旁边的button来判断可用性(程序中假设均可用,显示正确符号),在用户输入的所有信息都不为空时,点击button执行注册验证,启动动画,在新线程中模拟从远程验证用户信息的方法(程序中sleep(2000)假设验证失败),刷新界面组件。
三、具体实现
二、基本组件和原理
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() { @Override public 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() { @Override public 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() { @Override public 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>
相关文章推荐
- Android用户注册界面简单设计
- 【Android】用户登录注册界面开发及用户信息管理案例代码详解
- 【Android】用户登录注册界面开发及用户信息管理案例代码详解
- 【Android】用户登录注册界面开发及用户信息管理案例代码详解
- 【Android】用户登录注册界面开发及用户信息管理案例代码详解
- Android用户登录注册界面开发及用户信息管理案例代码详解
- 【Android】用户登录注册界面开发及用户信息管理案例代码详解
- Android注册界面之Md5对用户信息加密
- Android用户简单注册
- 【Android初学者】超简单的注册页面,填写完整信息实现 跳转 和 传参
- SharedPerferences 保存数据,android提供用于保存简单配置信息,标记,用户数据的一种方式
- Android之QQ新用户注册界面1
- 代码测试:简单用户注册信息验证
- Android简单登入注册界面的实现
- CSDN第一天——简单的登录注册及针对不同用户显示不同界面
- js简单实现用户注册信息的校验代码
- Android视频播放项目总结之 适配器绑定视频信息列表显示到界面(适配器简单优化)
- android 用户注册界面
- InstallScript工程注册用户信息界面中如何忽略公司信息
- 【代码生成Android布局】例.用户信息界面的生成