注册页面:

user_register.xml:

<?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"android:background="@drawable/bg_01">"<TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="注册"android:textSize="22dip"android:textColor="#FFFFFF"android:paddingLeft="140dip"android:paddingRight="50dip"android:paddingTop="10dip"android:background="@drawable/topbg"/>"<EditText android:id="@+id/register_username"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="20dip"android:background="@drawable/search" android:layout_marginLeft="20dip"android:layout_marginRight="20dip"android:height="40dip"android:hint="用户名"/><EditText android:id="@+id/register_passwd"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="20dip"android:background="@drawable/search" android:layout_marginLeft="20dip"android:layout_marginRight="20dip"android:height="40dip"android:hint="密码"/><EditText android:id="@+id/reregister_passwd"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="20dip"android:background="@drawable/search" android:layout_marginLeft="20dip"android:layout_marginRight="20dip"android:height="40dip"android:hint="确认密码"/><Button android:id="@+id/register_submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/topbg"android:height="40dip"android:width="70dip"android:layout_marginTop="60dip"android:text="确定"android:textColor="#FFFFFF"android:textSize="22dip"/></LinearLayout>

处理注册页面的Activity:

package com.example.foreveross.office;import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;import com.example.wenandroid.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;public class UserRegister extends Activity {private EditText register_username;
private EditText register_passwd;
private EditText reregister_passwd;
private Button register_submit;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();StrictMode.setThreadPolicy(policy);setContentView(R.layout.user_register);register_username=(EditText)findViewById(R.id.register_username);register_passwd=(EditText)findViewById(R.id.register_passwd);reregister_passwd=(EditText)findViewById(R.id.reregister_passwd);register_submit=(Button)findViewById(R.id.register_submit);register_username.setOnFocusChangeListener(new OnFocusChangeListener(){@Overridepublic void onFocusChange(View v, boolean hasFocus) {// TODO Auto-generated method stubif(!hasFocus){if(register_username.getText().toString().trim().length()<4){Toast.makeText(UserRegister.this, "用户名不能小于4个字符", Toast.LENGTH_SHORT).show();}}}});register_passwd.setOnFocusChangeListener(new OnFocusChangeListener(){@Overridepublic void onFocusChange(View v, boolean hasFocus) {// TODO Auto-generated method stubif(!hasFocus){if(register_passwd.getText().toString().trim().length()<6){Toast.makeText(UserRegister.this, "密码不能小于8个字符", Toast.LENGTH_SHORT).show();}}}});reregister_passwd.setOnFocusChangeListener(new OnFocusChangeListener(){@Overridepublic void onFocusChange(View v, boolean hasFocus) {// TODO Auto-generated method stubif(!hasFocus){if(!reregister_passwd.getText().toString().trim().equals(register_passwd.getText().toString().trim())){Toast.makeText(UserRegister.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show(); }}}});register_submit.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {if(!checkEdit()){return;}// TODO Auto-generated method stubString httpUrl="http://192.168.1.100:8080/web-test/register.jsp";HttpPost httpRequest=new HttpPost(httpUrl);List<NameValuePair> params=new ArrayList<NameValuePair>();params.add(new BasicNameValuePair("username",register_username.getText().toString().trim()));params.add(new BasicNameValuePair("password",register_passwd.getText().toString().trim()));HttpEntity httpentity = null;try {httpentity = new UrlEncodedFormEntity(params,"utf8");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}httpRequest.setEntity(httpentity);HttpClient httpclient=new DefaultHttpClient();HttpResponse httpResponse = null;try {httpResponse = httpclient.execute(httpRequest);} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}if(httpResponse.getStatusLine().getStatusCode()==200){String strResult = null;try {strResult = EntityUtils.toString(httpResponse.getEntity());} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}Toast.makeText(UserRegister.this, strResult, Toast.LENGTH_SHORT).show();}else{Toast.makeText(UserRegister.this, "请求错误", Toast.LENGTH_SHORT).show();}}});}private boolean checkEdit(){if(register_username.getText().toString().trim().equals("")){Toast.makeText(UserRegister.this, "用户名不能为空", Toast.LENGTH_SHORT).show();}else if(register_passwd.getText().toString().trim().equals("")){Toast.makeText(UserRegister.this, "密码不能为空", Toast.LENGTH_SHORT).show();}else if(!register_passwd.getText().toString().trim().equals(reregister_passwd.getText().toString().trim())){Toast.makeText(UserRegister.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show();}else{return true;}return false;}}

登录页面xml:

user_login.xml:

<?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" android:background="@drawable/bg_01"><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="登录"android:textSize="22dip"android:textColor="#FFFFFF"android:paddingLeft="140dip"android:paddingRight="50dip"android:paddingTop="10dip"android:background="@drawable/topbg"/><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="vertical" ><EditTextandroid:id="@+id/login_username"android:layout_width="fill_parent"android:layout_height="40dip"android:layout_marginLeft="20dip"android:layout_marginRight="20dip"android:layout_marginTop="30dip"android:hint="用户名"android:paddingTop="10dip"android:textSize="18dip"android:background="@drawable/search"></EditText><EditTextandroid:id="@+id/login_password"android:layout_width="fill_parent"android:layout_height="40dip"android:layout_marginLeft="20dip"android:layout_marginRight="20dip"android:layout_marginTop="10dip"android:password="true"android:paddingTop="10dip"android:textSize="18dip"android:hint="密码"android:background="@drawable/search"></EditText></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="15dip"><CheckBoxandroid:id="@+id/cb1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="50dip"android:layout_marginRight="30dip"android:text="记住密码" android:button="@drawable/checkbox_icon_no" />"<CheckBoxandroid:id="@+id/cb2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="自动登录" android:paddingRight="50dip"android:button="@drawable/checkbox_icon_no"/></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="20dip"><Button android:id="@+id/user_login_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="登录"android:layout_marginLeft="50dip"android:textColor="#F7FBFD"android:background="#FF0000"android:width="70dip"android:height="40dip"android:textSize="18dip"/><Button android:id="@+id/user_register_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="注册"android:layout_marginLeft="50dip"android:textColor="#F7FBFD"android:width="70dip"android:height="40dip"android:background="#0F9000"android:textSize="18dip"/></LinearLayout></LinearLayout>

登录页面Activity:

package com.example.foreveross.office;import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;import com.example.wenandroid.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;public class UserLogin extends Activity implements OnClickListener {
private EditText login_username;
private EditText login_password;
private Button user_login_button;
private Button user_register_button;@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();StrictMode.setThreadPolicy(policy);setContentView(R.layout.user_login);initWidget();}private void initWidget(){login_username=(EditText)findViewById(R.id.login_username);login_password=(EditText)findViewById(R.id.login_password);user_login_button=(Button)findViewById(R.id.user_login_button);user_register_button=(Button)findViewById(R.id.user_register_button);user_login_button.setOnClickListener(this);user_register_button.setOnClickListener(this);login_username.setOnFocusChangeListener(new OnFocusChangeListener(){@Overridepublic void onFocusChange(View v, boolean hasFocus) {// TODO Auto-generated method stubif(!hasFocus){String username=login_username.getText().toString().trim();if(username.length()<4){Toast.makeText(UserLogin.this, "用户名不能小于4个字符", Toast.LENGTH_SHORT);}}}});login_password.setOnFocusChangeListener(new OnFocusChangeListener(){@Overridepublic void onFocusChange(View v, boolean hasFocus) {// TODO Auto-generated method stubif(!hasFocus){String password=login_password.getText().toString().trim();if(password.length()<4){Toast.makeText(UserLogin.this, "密码不能小于4个字符", Toast.LENGTH_SHORT);}}}});}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch(v.getId()){case R.id.user_login_button:if(checkEdit()){login();}break;case R.id.user_register_button:Intent intent2=new Intent(UserLogin.this,UserRegister.class);startActivity(intent2);break;}}private boolean checkEdit(){if(login_username.getText().toString().trim().equals("")){Toast.makeText(UserLogin.this, "用户名不能为空", Toast.LENGTH_SHORT).show();}else if(login_password.getText().toString().trim().equals("")){Toast.makeText(UserLogin.this, "密码不能为空", Toast.LENGTH_SHORT).show();}else{return true;}return false;}private void login(){String httpUrl="http://192.168.1.102:8080/web-test/login.jsp";HttpPost httpRequest=new HttpPost(httpUrl);List<NameValuePair> params=new ArrayList<NameValuePair>();params.add(new BasicNameValuePair("username",login_username.getText().toString().trim()));params.add(new BasicNameValuePair("password",login_password.getText().toString().trim()));HttpEntity httpentity = null;try {httpentity = new UrlEncodedFormEntity(params,"utf8");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}httpRequest.setEntity(httpentity);HttpClient httpclient=new DefaultHttpClient();HttpResponse httpResponse = null;try {httpResponse = httpclient.execute(httpRequest);} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}if(httpResponse.getStatusLine().getStatusCode()==200){String strResult = null;try {strResult = EntityUtils.toString(httpResponse.getEntity());} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}Toast.makeText(UserLogin.this, strResult, Toast.LENGTH_SHORT).show();Intent intent=new Intent(UserLogin.this,IndexActivity.class);startActivity(intent);}else{Toast.makeText(UserLogin.this, "登录失败!", Toast.LENGTH_SHORT).show();}}
}

登录成功则跳转到IndexActivity.java

源自:http://www.cnblogs.com/dyllove98/p/3235407.html

转载于:https://www.cnblogs.com/zhang--xiang/p/4760606.html

android 注册、登录实现程序相关推荐

  1. Android注册登录页面

    Android注册登录页面 需求 分析 项目目录 .java domain JsonBean.java UserInfo.java utils GetJsonDataUtil.java Login.j ...

  2. java注册登录小程序,详解小程序之简单登录注册表单验证

    这段时间在做员工管理的小程序,前期在登录注册上花了不少功夫,今天就给大家分享下. 效果图,wxss的内容较简单,自己编写即可. ##主要内容 一.首先我是在util.js中引入表单正则验证规则,给予l ...

  3. c语言编写邮箱注册登录的程序,c语言实现邮箱地址验证

    rfc中是这样定义邮箱格式的: address = mailbox ; one addressee / group ; named list group = phrase ":" ...

  4. android注册的模板下载地址,Android --LoginActivity模板登录

    Android Studio使用自带LoginActivity模板,制作登录界面 登录界面功能: 1.记住表单账户密码,并自动登录 //获得sp实例对象 sp = this.getSharedPref ...

  5. Android实现注册登录头像上传等功能常规开发(Android端,服务器端开发实例)

    Android实现注册登录头像上传等功能常规开发(Android端,服务器端开发实例) 标签: 注册登录Android开发servlet 2017-04-18 20:34  454人阅读  评论(1) ...

  6. Android用户登录注册界面

    用户登录注册界面开发及用户信息管理案例详解 刚开始接触Android编程,这算是我写的第一个简单工程,主要功能有:用户登录.注册.注销.修改密码.记住密码共5个基本操作,其内容涉及到以下几点: 1:B ...

  7. python用户登录程序_「Python」每日一练:函数的应用之注册登录程序

    编程题 函数的应用之注册登录程序 任务内容:要求模拟系统注册及登录的情境,注册密码要求:密码是6位或以上,必须包涵大写字母.小写字母.数字.程序若未退出前,则一直循环运行. 程序编写要求:按要求完善各 ...

  8. 微信小程序注册/登录接口开发

    文章目录 后端有关说明 前端有关说明 接口设计 小程序注册/登录接口 APP 注册/登录接口 PC Web 端的注册/登录接口 小程序注册/登录序列图 校验 token 后端有关说明 登录和注册的逻辑 ...

  9. Android开发学习——记单词APP安卓注册登录跳转

    登陆页面XML <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayo ...

最新文章

  1. Java 集合系列(4): LinkedList源码深入解析2
  2. 【学习笔记】Tableau基础介绍
  3. 测试工具_10款优秀的浏览器兼容性测试工具
  4. HTML+CSS+JS实现canvas仿ps橡皮擦刮卡效果
  5. mysql查询2个isbn数据,数据库实验二 数据查询
  6. 设计灵感|引导页设计中如何借助图形来展现场景?
  7. [论文]Clustering-Based Ensembles as an Alternative to Stacking
  8. nutch batchid
  9. Y-Combinator不同语言实现方案
  10. 黑客入侵电脑网络四大步骤
  11. 罗技产品序列号追溯条码扫描系统
  12. [历史随笔]帝国如风--元朝的另类历史
  13. linux查找文件中的字符串
  14. UOJ #455.【UER #8】雪灾与外卖 堆模拟费用流
  15. 腾讯云常见云产品中的云硬盘(块存储)、文件存储、对象存储三者的区别!
  16. 服务器android打包,在服务器上使用 gradle 打包 android 源码
  17. 我,喜提招商银行,当爹啦
  18. MATLAB Symbolic Math Toolbox
  19. 关于网站广告被拦截说明
  20. UML画图文档之汇总

热门文章

  1. Android性能优化常见问题,附架构师必备技术详解
  2. python【数据结构与算法】01背包问题(附例题)
  3. python【蓝桥杯vip练习题库】BASIC-11 十六进制转十进制
  4. 华为鸿蒙系统支持智慧多屏吗,搭载鸿蒙OS!华为宣布企业智慧屏:多屏协同、底座带轮子...
  5. 怎样利用超图客户端打点_渗透测试——XSS利用工具BeEF攻击演示
  6. 浅析网站开发的未来前景如何?
  7. 外贸网站建设需要考虑的五大层面
  8. 哪一类功率放大电路效率最高_电路分析基础(8)-最大功率传输与阻抗匹配分析...
  9. python调用数据集mnist_Python读取MNIST数据集
  10. 内网使用ohmyzsh