标签:
这两天一直在写登陆,还要可以自动登录,着实让小白我觉得头疼啊。但是代码就是一行行写出来,加油。这里记录下之前用的方式,弹出对话框,但这样写自动登陆的时候不太好写,所以现在要大概。但之前写对话框的时候也费了翻功夫,谁让是小白呢。还是记录下,留个参考
// 队员点击item登陆,判断时候登陆,以及登陆是否正确
public void teamDialog() {
Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
if (flag == 1) {
alertDialog.setTitle("用户登陆:");
alertDialog.setIcon(R.drawable.btn_star_team);
alertDialog.setPositiveButton("登陆",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PostData() ;
}
});
} else if (flag == 0) {
alertDialog.setTitle("队长登录:");
alertDialog.setIcon(R.drawable.btn_star_captain);
alertDialog.setPositiveButton("登录",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 判断是否通过,通过则跳出特权页
}
});
}
alertDialog.setView(DialogView);
alertDialog.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.create();
UIUtils.removeParent(DialogView);
alertDialog.show();
}
/**
* 当用户点击登录按钮时出发的事件
*/
public void teamLogin(){
userNunberValue = user_number.getText().toString() ;
userPassValue = user_password.getText().toString() ;
LoginNetwork network = new LoginNetwork() ;
HashMap<String, String> map = new HashMap<String, String>() ;
if(userNunberValue.equals("")||userPassValue.equals("")){
result = 0 ;
}else{
map.put("number", userNunberValue) ;
map.put("password", userPassValue) ;
result = network.load(1,map) ;
}
}
/**
* 传送数据服务器接口
*/
public void PostData(){
ThreadManager.getInstance().createLongPool().execute(new Runnable() {
@Override
public void run() {
teamLogin() ;
UIUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (result != 0) {
Toast.makeText(UIUtils.getContext(), "登录成功!", Toast.LENGTH_LONG).show() ;
// //传递一个参数给me_fragment的详情页,让其显示当前用户的信息
Bundle data = new Bundle() ;
data.putString("tag", userNunberValue) ;
meFragment = new MeFragment() ;
meFragment.setArguments(data) ;
}else{
Toast.makeText(UIUtils.getContext(), "¥_¥ 登录失败,请重新登录!", Toast.LENGTH_LONG).show() ;
}
}
});
}
});
}
标签:
原文地址:http://www.cnblogs.com/heartstong/p/4781302.html