Android:注册登录
注册登录的实现
先在layout里新建一个xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1">
<TableRow>
<TextView android:text="用户名称:" android:id="@+id/TextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text="" android:id="@+id/userEditText"
android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText>
</TableRow>
<TableRow>
<TextView android:text="用户密码:" android:id="@+id/TextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text="" android:id="@+id/pwdEditText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:password="true"></EditText>
</TableRow>
<TableRow android:gravity="right">
<Button android:text="取消" android:id="@+id/cancelButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="登陆" android:id="@+id/loginButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
然后在java代码里实现控件的功能:
public class AndroidWorld extends Activity {
private Button cancelBtn,loginBtn;
private EditText userEditText,pwdEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
cancelBtn = (Button)findViewById(R.id.cancelButton);
loginBtn = (Button)findViewById(R.id.loginButton);
userEditText = (EditText)findViewById(R.id.userEditText);
pwdEditText = (EditText)findViewById(R.id.pwdEditText);
cancelBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
loginBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(validate()){
if(login()){
Intent intent = new Intent(AndroidWorld.this,LoginSuccess.class);
startActivity(intent);
}else{
showDialog("用户名称或者密码错误,请重新输入!");
}
}
}
});
}
private boolean login(){
String username = userEditText.getText().toString();
String pwd = pwdEditText.getText().toString();
String result=query(username,pwd);
if(result!=null&&result.equals("1")){
return true;
}else{
return false;
}
}
private boolean validate(){
String username = userEditText.getText().toString();
if(username.equals("")){
showDialog("用户名称是必填项!");
return false;
}
String pwd = pwdEditText.getText().toString();
if(pwd.equals("")){
showDialog("用户密码是必填项!");
return false;
}
return true;
}
private void showDialog(String msg){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
private String query(String username,String password){
String queryString = "username="+username+"&password="+password;
String url = HttpUtil.BASE_URL+"servlet/LoginServlet?"+queryString;
return HttpUtil.queryStringForPost(url);
}
}
参考资料链接:
代码下载链接: http://www.apkbus.com/android-139324-1-1.html
http://www.apkbus.com/android-139325-1-1.html
http://www.apkbus.com/android-139361-1-1.html
http://www.apkbus.com/android-139375-1-1.html
Android:注册登录的更多相关文章
- 基于后端云的Android注册登录开发
APP开发离不开注册登录功能,但是注册登录功能开发需要后台数据库的支持,对于一些初学者或者对后台数据 不熟悉的同学来说可能会有些困难.本文介绍一下后端云: 1. Bmob是国内起步较早的云后端服务平台 ...
- android 注册、登录实现程序
注册页面: user_register.xml: <?xml version="1.0" encoding="utf-8"?> <Linear ...
- Android 比较好看的注册登录界面
各位看官姥爷: 对于一款android手机app而言,美观的界面使得用户有好的使用体验,而一款好看的注册登录界面也会给用户好的用户体验,那么话不多说,直接上代码 首先是一款简单的界面展示 1.登陆界面 ...
- Android开发案例 - 注册登录
本文只涉及UI方面的内容, 如果您是希望了解非UI方面的访客, 请跳过此文. 在微博, 微信等App的注册登录过程中有这样的交互场景(如下图): 打开登录界面 在登录界面中, 点击注册, 跳转到注册界 ...
- Android之登录时密码的保护
在很多的Android项目中都需要用户登录.注册.这样的话在开发中做好保护用户密码的工作就显得尤为重要.这里我把自己的密码保护方法记录下来. 这是我建了一个保存密码的文件,以便于检查自己保存密码或者上 ...
- Android实现登录
登录界面布局文件 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...
- Android SharedPreferences登录记住密码
SharedPreferences是Android中存储简单数据的一个工具类.可以想象它是一个小小的Cookie,它通过用键值对的方式把简单 数据类型(boolean.int.float.long和S ...
- Android微信登录、分享、支付
转载需要著名出处: http://blog.csdn.net/lowprofile_coding/article/details/78004224 之前写过微信登录分享支付第一版: http://bl ...
- Androidの共享登录之方案研究
由于最近公司提到了一个需求是,一个应用登录成功了,另一个自动登录. 绞尽脑汁想了好几天,看起来很容易但是想深点就漏洞百出,有的时候代码都写完了测试都成功了突然发现给一个假设就完全失效. 先前几个同事之 ...
随机推荐
- javascript面向对象精要第一章原始类型和引用类型整理精要
- poj 2785(折半枚举+二分搜索)
传送门:Problem 2785 题意: 给定 n 行数,每行都有 4 个数A,B,C,D. 要从每列中各抽取出一个数,问使四个数的和为0的所有方案数. 相同数字不同位置当作不同数字对待. 题解: 如 ...
- P1450 [HAOI2008]硬币购物
题目描述 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买si的价值的东西.请问每次有多少种付款方法. di,s<=100000 ...
- Hadoop基础-HDFS安全管家之Kerberos实战篇
Hadoop基础-HDFS安全管家之Kerberos实战篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们都知道hadoop有很多不同的发行版,比如:Apache Hadoop ...
- Request库学习
0x00前言 这库让我爱上了python 碉堡! 开心去学了一些python,然后就来学这个时候神库~~ 资料来源:http://cn.python-requests.org/en/latest/u ...
- POJ - 1836 Alignment (动态规划)
https://vjudge.net/problem/POJ-1836 题意 求最少删除的数,使序列中任意一个位置的数的某一边都是递减的. 分析 任意一个位置的数的某一边都是递减的,就是说对于数h[i ...
- numpy笔记—np.sum中keepdims作用
A = np.random.randn(4,3) B = np.sum(A, axis = 1, keepdims = True) 我们使用(keepdims = True)来确保 A.shape 是 ...
- python多进程那点事儿【multiprocessing库】
前言:项目中有个需求需要对产品的日志处理,按照产品中日志的某些字段,对日志进行再次划分.比如产品的日志中含有字段id,tag=1,现在需要把tag是基数的放到一个文件中,tag是偶数的放入一个文件中. ...
- C#检测鼠标移动消息
当C#窗口上有其它控件时,窗口本身检测不到消息.1.使用WndProc.MouseMove不行,比如 protected override void WndProc(ref Message m) { ...
- 2.SpringBoot HelloWorld详解
1.POM文件 父项目 <parent> <groupId>org.springframework.boot</groupId> <artifactId> ...