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の共享登录之方案研究
由于最近公司提到了一个需求是,一个应用登录成功了,另一个自动登录. 绞尽脑汁想了好几天,看起来很容易但是想深点就漏洞百出,有的时候代码都写完了测试都成功了突然发现给一个假设就完全失效. 先前几个同事之 ...
随机推荐
- redis实现队列
转:https://www.cnblogs.com/nullcc/p/5924244.html 问题:如果一个并发很大的消息应用,想要根据请求的优先级来处理? 答案:用Redis 详解: 一是并发量大 ...
- (大数 求余) Large Division Light OJ 1214
Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...
- 使用ROP攻击绕过Windows的DEP
使用ROP攻击绕过Windows的DEP 基础知识 DEP DEP(Data Execution Prevention)意为数据执行保护,是Windows的一项安全机制,主要能够在内存上执行额外检查以 ...
- 用socket写一个简单的客户端和服务端程序
用来练手写写socket代码 客户端代码 #include <stdio.h> #include <sys/types.h> #include <sys/socket.h ...
- CentOS 6.5 升级内核
Docker需要3.10以上内核支持,Centos6.5 默认内核为2.6.所以手动编译安装3.10内核. 查看当前系统内核版本 [root@gu ~]# uname -r2.6.32-431.el6 ...
- MySQL_DDL(不定时更新)
1. //1.创建数据库,并指定字符集为utf8 create database rocker_oa default character set utf8; //2.创建用户,并指定密码为‘root’ ...
- C#修饰符详解
不定期更新,2017.8.9 一.new 别看new这个修饰符经常用,恐怕很多人都不知道其本质.我们先来看看new修饰符的官方定义: new 仅允许在嵌套类声明中使用,表明类中隐藏了由基类中继承而来的 ...
- 标准遗传算法(二进制编码 python实现)
代码地址:https://github.com/guojun007/binary_sga 种群初始化: binary_sga/population_init/population_init.py #种 ...
- 学习windows编程 day6 之处理鼠标移动
#define POINT_MAX 1000 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPara ...
- springSession框架来实现sso单点登陆
介绍一下springsession这个框架,其实springsession框架默认的是使用redis来实现单点登陆的,但是不支持redis集群,这个框架的特点是无侵入的实现单点登陆,就是说我们之前获取 ...