android怎么实现注册登录程序
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这篇文章主要介绍"android怎么实现注册登录程序"的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇"android怎么实现注册登录程序"文章能帮助大家解决问题。
千家信息网最后更新 2026年11月02日android怎么实现注册登录程序
这篇文章主要介绍"android怎么实现注册登录程序"的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇"android怎么实现注册登录程序"文章能帮助大家解决问题。
注册页面:
user_register.xml:
" "
处理注册页面的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; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.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() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if(!hasFocus){ if(register_username.getText().toString().trim().length()<4){ Toast.makeText(UserRegister.this, "用户名不能小于4个字符", Toast.LENGTH_SHORT).show(); } } } }); register_passwd.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if(!hasFocus){ if(register_passwd.getText().toString().trim().length()<6){ Toast.makeText(UserRegister.this, "密码不能小于8个字符", Toast.LENGTH_SHORT).show(); } } } }); reregister_passwd.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if(!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(){ @Override public void onClick(View v) { if(!checkEdit()){ return; } // TODO Auto-generated method stub String httpUrl="http://192.168.1.100:8080/web-test/register.jsp"; HttpPost httpRequest=new HttpPost(httpUrl); List params=new ArrayList(); 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 block e.printStackTrace(); } httpRequest.setEntity(httpentity); HttpClient httpclient=new DefaultHttpClient(); HttpResponse httpResponse = null; try { httpResponse = httpclient.execute(httpRequest); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(httpResponse.getStatusLine().getStatusCode()==200) { String strResult = null; try { strResult = EntityUtils.toString(httpResponse.getEntity()); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.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; } } 登录页面:
user_login.xml:
"
登录页面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; @Overrideprotected 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() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if(!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() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if(!hasFocus){ String password=login_password.getText().toString().trim(); if(password.length()<4){ Toast.makeText(UserLogin.this, "密码不能小于4个字符", Toast.LENGTH_SHORT); } } } }); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(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 params=new ArrayList(); 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 block e.printStackTrace(); } httpRequest.setEntity(httpentity); HttpClient httpclient=new DefaultHttpClient(); HttpResponse httpResponse = null; try { httpResponse = httpclient.execute(httpRequest); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(httpResponse.getStatusLine().getStatusCode()==200) { String strResult = null; try { strResult = EntityUtils.toString(httpResponse.getEntity()); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.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
关于"android怎么实现注册登录程序"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注行业资讯频道,小编每天都会为大家更新不同的知识点。
登录
密码
字符
用户
用户名
程序
知识
页面
一致
行业
输入
不同
实用
成功
内容
册页
实用性
实际
文章
方法
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
为想互联网科技怎么样
云信互联网科技有限公司
互联网科技有限公司经营范围
奇酷互联网科技
善班互联网科技有限公司
奇士达互联网科技
互联网女皇 腾讯科技
科技互联网创业计划书
农村开互联网科技讲堂
中国科技创新与世界互联网大会
洛阳共同富裕互联网科技有限公司
济南有互联网科技公司吗
上海科技产业互联网平台
银行科技岗属于互联网吗
广州百诚互联网科技有限公司官网
广西科技产业互联网是什么
云南互联网科技学费
同城互联网络科技
中国主要互联网科技公司
如何强化互联网金融科技
百单网互联网科技有限公司怎么样
山东特亿宝互联网科技有限公司
华宇互联网科技
狮子座互联网科技有限公司
哈尔滨新华互联网科技
温州喔噻互联网科技有限公司
江阴互联网智能科技产品进口
宜昌元轩互联网科技有限公司
注册互联网科技公司经营范围大全
互联网科技如何创业