简单的本地验证
来源:互联网 发布:直销双轨奖金制度算法 编辑:程序博客网 时间:2024/05/17 02:00
本实验是简单的登录界面—EditText编辑框的应用,在该界面中,若输入正确的用户名(假设为e1001)和密码(假设为1234567),单击“确定”按钮,将出现一个Toast提示“恭喜您登录成功!”;否则将提示“请输入正确的用户名或密码!”。单击“清空”按钮,则会清空所填写的姓名和密码内容。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.hades.homework5.MainActivity"> <LinearLayout android:layout_width="374dp" android:layout_height="497dp" android:orientation="vertical" tools:layout_editor_absoluteY="6dp" tools:layout_editor_absoluteX="8dp"> <LinearLayout android:layout_width="374dp" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.77" android:text="用户名" android:textSize="20dp" /> <EditText android:id="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="textPersonName" android:text="e10001" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" tools:layout_editor_absoluteX="8dp" tools:layout_editor_absoluteY="8dp"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="密码" android:textSize="20dp" /> <EditText android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="textPassword" android:text="1234567" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="登录" /> <Button android:id="@+id/clear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="清除" /> </LinearLayout> </LinearLayout></android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.hades.homework5;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends AppCompatActivity { Button login, clear; TextView username, password; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); login = (Button) findViewById(R.id.login); clear = (Button) findViewById(R.id.clear); username = (TextView) findViewById(R.id.username); password = (TextView) findViewById(R.id.password); login.setOnClickListener(new click1()); clear.setOnClickListener(new click2()); } private class click1 implements View.OnClickListener { @Override public void onClick(View v) { if (username.toString().isEmpty() || password.toString().isEmpty()) { Toast.makeText(getApplicationContext(), "请填写完整", Toast.LENGTH_SHORT).show(); } else { if (username.getText().toString().equals("e10001") && password.getText().toString().equals("1234567")) { Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "用户名或密码错误", Toast.LENGTH_SHORT).show(); } } } } private class click2 implements View.OnClickListener { @Override public void onClick(View v) { username.setText(""); password.setText(""); } }}
阅读全文
0 0
- 简单的本地验证
- android之简单好用的本地生成验证码并进行验证
- 本地验证码的实现
- 简单的客户端验证
- 简单的验证
- 简单的验证码
- 简单的Jquery验证
- 简单的验证码
- 简单的表单验证
- 简单的验证码
- 简单的验证
- 身份证号码的简单验证
- 简单的登录验证
- 简单的验证码
- 简单的 表单验证
- 简单的验证邮箱
- 简单的图片验证
- 简单的表单验证
- 【一头扎进JMS】(2)----ActiviteMQ点对点消息实现
- B树的实现
- letex使用方法
- Treap 全操作模板 bzoj 3224 普通平衡树
- R语言集成学习
- 简单的本地验证
- LeetCode-70. Climbing Stairs
- C语言作业-3-1奇偶个数
- Kotlin for Android
- Python与Excel之一 xlrd读取excel
- 高并发Java(4):无锁
- Y2K Accounting Bug poj
- Tomcat8中开启gzip压缩功能的配置方法
- js短信注册