android登录功能
来源:互联网 发布:学编程看什么书 编辑:程序博客网 时间:2024/06/05 18:24
简单的登录逻辑代码
[1].[代码] [Java]代码 跳至 [1]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package
com.example.mifi;
import
java.util.HashMap;
import
java.util.Map;
import
org.json.JSONObject;
import
android.app.Activity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.EditText;
import
com.example.mifi.utils.DialogUtil;
import
com.example.mifi.utils.HttpUtil;
public
class
Login
extends
Activity {
EditText etName, etPass;
Button bnLogin, bnCancel;
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.login);
etName = (EditText) findViewById(R.id.userEditText);
etPass = (EditText) findViewById(R.id.pwdEditText);
bnLogin = (Button) findViewById(R.id.bnLogin);
bnCancel = (Button) findViewById(R.id.bnCancel);
bnLogin.setOnClickListener(
new
OnClickListener() {
public
void
onClick(View v) {
if
(!validate())
return
;
if
(loginPro()) {
Intent intent =
new
Intent(Login.
this
, Main.
class
);
startActivity(intent);
finish();
return
;
}
DialogUtil.showDialog(Login.
this
,
"用户名或密码错误,请重新输入!"
,
false
);
}
});
}
/**
* 验证登录帐号
*/
private
boolean
loginPro() {
String username = etName.getText().toString().trim();
String password = etPass.getText().toString().trim();
JSONObject jsonObj;
try
{
jsonObj = Query(username, password);
if
(jsonObj.getBoolean(
"success"
))
return
true
;
}
catch
(Exception e) {
DialogUtil.showDialog(
this
,
"服务器响应异常,请稍后再试!"
,
false
);
e.printStackTrace();
}
return
false
;
}
/**
* 验证用户名密码
*/
private
JSONObject Query(String username, String password)
throws
Exception {
Map<String, String> map =
new
HashMap<String, String>();
map.put(
"username"
, username);
map.put(
"password"
, password);
String url = HttpUtil.BASE_URL +
"client/login/"
;
return
new
JSONObject(HttpUtil.doPost(url, map));
}
/**
* 输入为空
*/
private
boolean
validate() {
String username = etName.getText().toString().trim();
String password = etPass.getText().toString().trim();
if
(
""
.equals(username)) {
DialogUtil.showDialog(
this
,
"请输入用户名!"
,
false
);
return
false
;
}
if
(
""
.equals(password)) {
DialogUtil.showDialog(
this
,
"请输入用户密码!"
,
false
);
return
false
;
}
return
true
;
}
}
0 0
- android登录功能
- Android 登录注册功能
- android 单点登录功能
- Android登录功能实现
- Android 退出登录功能
- Android 实现登录注册功能
- android 登录界面功能实现
- Android 实现登录注册功能
- Android登录注册功能封装
- android登录和设置IP/端口功能
- Android 实现登录界面和功能实例
- Android PHP JSON 登录注册功能实现
- Android实现登录界面和功能实例
- Android实现登录界面和功能实例
- android 自动登录功能的实现
- Android开发登录功能那些事儿
- android 手把手教你接微信登录功能
- Android 实现登录界面和功能实例
- 曾经,和兄弟们一起相信未来!
- Longest Valid Parentheses
- 永不停息的红舞步一个电子工程师的心路历程(转载)
- 需求文档可以不签字吗之二-理论推导
- python 笔记 在windows下的程序 获取图片并显示出来
- android登录功能
- c++_primer_exercise_1118
- 网球之球拍的材质及参数
- 深入理解内联inline函数的优缺点,性能及使用指南
- Java-Maximum Gap
- Python 第四章 字典:当索引不好用时
- 黑马程序员--Java基础知识总结
- C++ 面向对象编程 友元类成员函数
- 灵活使用XMultipleSeriesRenderer设置自定义的轴标签