首页 > 其他分享 >2024.03.12

2024.03.12

时间:2024-03-12 10:12:15浏览次数:13  
标签:Toast 12 2024.03 void new msg import android

       

  第5天
所花时间(包括上课) 2h
代码量(行) 140行
博客量(篇) 1篇
学习到的知识点 页面的跳转,和注册页面,登录页面的构建

 

 

 

 

 

 

 

package com.example.myapplication1;


import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.myapplication1.dao.UserDao;
import com.example.myapplication1.entity.User;

/**
 * function:连接注册页面
 */
public class activity_register extends AppCompatActivity {
    private static final String TAG = "mysql-application1-register";
    EditText userAccount = null;
    EditText userPassword = null;
    EditText userName = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        userAccount = findViewById(R.id.userAccount);
        userPassword = findViewById(R.id.userPassword);
        userName = findViewById(R.id.userName);
    }


    public void register(View view){

        String userAccount1 = userAccount.getText().toString();
        String userPassword1 = userPassword.getText().toString();
        String userName1 = userName.getText().toString();


        User user = new User();

        user.setUserAccount(userAccount1);
        user.setUserPassword(userPassword1);
        user.setUserName(userName1);
        user.setUserType(1);
        user.setUserState(0);
        user.setUserDel(0);

        new Thread(){
            @Override
            public void run() {

                int msg = 0;

                UserDao userDao = new UserDao();

                User uu = userDao.findUser(user.getUserAccount());
                if(uu != null){
                    msg = 1;
                }
                else{
                    boolean flag = userDao.register(user);
                    if(flag){
                        msg = 2;
                    }
                }
                hand.sendEmptyMessage(msg);

            }
        }.start();


    }
    @SuppressLint("HandlerLeak")
    final Handler hand = new Handler()
    {
        public void handleMessage(Message msg) {
            if(msg.what == 0) {
                Toast.makeText(getApplicationContext(),"注册失败",Toast.LENGTH_LONG).show();
            } else if(msg.what == 1) {
                Toast.makeText(getApplicationContext(),"该账号已经存在,请换一个账号",Toast.LENGTH_LONG).show();
            } else if(msg.what == 2) {
                Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_LONG).show();
                Intent intent = new Intent();
                //将想要传递的数据用putExtra封装在intent中
                intent.putExtra("a","注册");
                setResult(RESULT_CANCELED,intent);
                finish();
            }
        }
    };
}
package com.example.myapplication1;


import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.example.myapplication1.dao.UserDao;
/**
 * function:连接页面加载首页
 */
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "mysql-application1-MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void reg(View view){
        startActivity(new Intent(getApplicationContext(),activity_register.class));
    }


    /**
     * function: 登录
     * */
    public void login(View view){

        EditText EditTextAccount = findViewById(R.id.uesrAccount);
        EditText EditTextPassword = findViewById(R.id.userPassword);

        new Thread(){
            @Override
            public void run() {
                UserDao userDao = new UserDao();
                int msg = userDao.login(EditTextAccount.getText().toString(),EditTextPassword.getText().toString());
                hand1.sendEmptyMessage(msg);
            }
        }.start();

    }

    @SuppressLint("HandlerLeak")
    final Handler hand1 = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0){
                Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_LONG).show();
            } else if (msg.what == 1) {
                Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_LONG).show();
            } else if (msg.what == 2){
                Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_LONG).show();
            } else if (msg.what == 3){
                Toast.makeText(getApplicationContext(), "账号不存在", Toast.LENGTH_LONG).show();
            }
        }
    };
}

 

标签:Toast,12,2024.03,void,new,msg,import,android
From: https://www.cnblogs.com/dmx-03/p/18067695

相关文章

  • 12_享元模式
    享元模式是一种结构型设计模式,它通过共享细粒度的对象来最大限度地减少内存使用和对象创建的数量。享元模式通过将共享对象的状态外部化,使得对象可以共享,并提供了一个工厂类来管理共享对象的创建和获取。享元模式有五个主要角色:享元接口(Flyweight):定义了共享对象的接口,包含了需......
  • 3月12日 新榜情报
    3月12日新榜情报1.抖音2023年短剧付费用户增长超3倍,日均播放量同比增长100%2.抖音55场“超值天团”直播助力抖音商城38好物节3.快手校园联合快手美妆举办“开学爆改挑战”线下路演活动4.快手健康举办“关爱她健康”主题活动5.B站首页现可跳转淘宝直播间6.董宇辉带货华为总......
  • leetcode: 2129. 将标题首字母大写
    给你一个字符串 title ,它由单个空格连接一个或多个单词组成,每个单词都只包含英文字母。请你按以下规则将每个单词的首字母 大写 :如果单词的长度为 1 或者 2 ,所有字母变成小写。否则,将单词首字母大写,剩余字母变成小写。请你返回 大写后 的 title 。示例1:输入:ti......
  • 软件工程日报5 2024.03.11
     第一天第二天第三天第四天第五天所花时间(包括上课)6小时5小时4小时4小时 六小时代码量(行)300350200300 50博客量(篇)1111 1所学知识了解安卓相关数据库的知识,下载安装了matlab学习了相关安卓的布局展示了解activity之间的相互跳转以注册了......
  • 12. RS485通信协议
    一、RS485简介  RS485(一般称作RS485/EIA-485)隶属于OSI模型物理层,是串行通讯的一种。电气特性规定为2线,半双工,多点通信的类型。它的电气特性和RS-232大不一样。用缆线两端的电压差值来表示传递信号。RS485仅仅规定了接受端和发送端的电气特性。它没有规定或推荐任何数据......
  • debian12.5配置静态IP
    root@debian:~#cat/etc/network/interfaces##Thisfiledescribesthenetworkinterfacesavailableonyoursystem##andhowtoactivatethem.Formoreinformation,seeinterfaces(5).##source/etc/network/interfaces.d/*###Theloopbacknetworkinterface#aut......
  • Windows Server 2012R2 丢失api-ms-win-crt-runtime-l1-1-0.dll
    在网上搜索了很久,没有现成的帖子可以解决。安装补丁不是提示“一个或多个问题导致了安装失败”就是此更新不适用于你的计算机。最终在微软官网读到补丁安装要遵守一个顺序,在此特地把解决过程分享出来,希望能帮助到苦于搜索的人报错信息 无法启动此程序,因为计算机中丢失api-ms......
  • aspnet zero 12 添加登录 验证码
       aspnetzero自带的验证码是基于Google,国内当前无法使用,只能替换国内的。实现后的界面如下图: PackageManagerInstall-PackageLazy.Captcha.Core验证码后端代码publicinterfaceICaptchaAppService:IApplicationService{///<summary>......
  • es12
    的ECMAScript(ES)标准是ES12,也被称为ES2022。ES2022于2021年发布,引入了一些新的语言特性和改进。以下是ES2022中的一些主要特性:String.prototype.replaceAll()方法:replaceAll()方法用于替换字符串中所有匹配的子字符串。javascriptCopyCodeconststr='Hello,Wor......
  • 在 Debian 12.5 上编译安装 Nginx
    1.更新系统软件包并安装必要的构建工具和依赖项:sudoaptupdatesudoaptupgradesudoaptinstallbuild-essentialzlib1g-devlibpcre3-devlibssl-devbash2.下载Nginx源码包:wgethttp://nginx.org/download/nginx-x.y.z.tar.gz#替换x.y.z为你要安装的Nginx版本号tar......