注册登录的实现

先在layout里新建一个xml文件:

//login.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:注册登录的更多相关文章

  1. 基于后端云的Android注册登录开发

    APP开发离不开注册登录功能,但是注册登录功能开发需要后台数据库的支持,对于一些初学者或者对后台数据 不熟悉的同学来说可能会有些困难.本文介绍一下后端云: 1. Bmob是国内起步较早的云后端服务平台 ...

  2. android 注册、登录实现程序

    注册页面: user_register.xml: <?xml version="1.0" encoding="utf-8"?> <Linear ...

  3. Android 比较好看的注册登录界面

    各位看官姥爷: 对于一款android手机app而言,美观的界面使得用户有好的使用体验,而一款好看的注册登录界面也会给用户好的用户体验,那么话不多说,直接上代码 首先是一款简单的界面展示 1.登陆界面 ...

  4. Android开发案例 - 注册登录

    本文只涉及UI方面的内容, 如果您是希望了解非UI方面的访客, 请跳过此文. 在微博, 微信等App的注册登录过程中有这样的交互场景(如下图): 打开登录界面 在登录界面中, 点击注册, 跳转到注册界 ...

  5. Android之登录时密码的保护

    在很多的Android项目中都需要用户登录.注册.这样的话在开发中做好保护用户密码的工作就显得尤为重要.这里我把自己的密码保护方法记录下来. 这是我建了一个保存密码的文件,以便于检查自己保存密码或者上 ...

  6. Android实现登录

    登录界面布局文件         1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...

  7. Android SharedPreferences登录记住密码

    SharedPreferences是Android中存储简单数据的一个工具类.可以想象它是一个小小的Cookie,它通过用键值对的方式把简单 数据类型(boolean.int.float.long和S ...

  8. Android微信登录、分享、支付

    转载需要著名出处: http://blog.csdn.net/lowprofile_coding/article/details/78004224 之前写过微信登录分享支付第一版: http://bl ...

  9. Androidの共享登录之方案研究

    由于最近公司提到了一个需求是,一个应用登录成功了,另一个自动登录. 绞尽脑汁想了好几天,看起来很容易但是想深点就漏洞百出,有的时候代码都写完了测试都成功了突然发现给一个假设就完全失效. 先前几个同事之 ...

随机推荐

  1. Hihocoder 1329 平衡树·Splay(平衡树)

    Hihocoder 1329 平衡树·Splay(平衡树) Description 小Ho:小Hi,上一次你跟我讲了Treap,我也实现了.但是我遇到了一个关键的问题. 小Hi:怎么了? 小Ho:小H ...

  2. Java: String.split(....); 结果很意外

    String txt = "join|公共聊天室||"; String[] paras = txt.splite("\\|"); String t1 = par ...

  3. MyEclipse中的Tomcat跑大项目时内存溢出:permgen space

    点击菜单栏的“Run”-"Run Configurations",在打开的窗口中点击“Arguments”选项卡. 在VM arguments中内容最下边(加上)输入:-Xms25 ...

  4. 约会 音频mm教你追女孩

    微信吧地址发给他人. 美团提前选好环境然后提前打电话订购一个位置. 微博作用是为:更多的谈资.热搜 ,最近上榜的话题说. 打车软件: 地图: 2.外表: 下澡,指甲,胡子,发型,适合服装.发型和服装搭 ...

  5. 【tools】vim删除命令

    x 删除当前光标下的字符dw 删除光标之后的单词剩余部分.d$ 删除光标之后的该行剩余部分.dd 删除当前行. c 功能和d相同,区别在于完成删除操作后进入INSERT MODEcc 也是删除当前行, ...

  6. 学习Git笔记

    一.名词解释 1.仓库(Repository) 仓库用来存放项目代码,每个项目对应一个仓库,多个开源项目则有多个仓库. 2.收藏(Star) 收藏项目,方便下次查看 3.复制克隆项目(Fork) 该f ...

  7. java keytool证书工具使用小结【转】

    java keytool证书工具使用小结 keytool导入导出多条目对比 在Security编程中,有几种典型的密码交换信息文件格式: DER-encoded certificate: .cer, ...

  8. golang数组声明

    格式 初始化数组 {}中的元素数不能大于[]中的数字,并且长度在初始化后不能改变,定义数组时需指定长度 ... var arrName [num]type = [num]type{value, val ...

  9. B+树,B树,聚集索引,非聚集索引

    简介: B+树中只有叶子节点会带有指向记录的指针,而B树则所有节点都带有 B+树索引可以分为聚集索引和非聚集索引 mysql使用B+树,其中Myisam是非聚集索引,innoDB是聚集索引 聚簇索引索 ...

  10. openvpn路由配置

    openvpn路由配置 通常openvpn部署好以后,客户端连接VPN后会被配置一些路由,其客户端的路由会被修改为所有的流量都通过VPN来传输.但有时候,我们需要客户端的某些IP走VPN或者本地网关. ...