首页 > 其他分享 >每日总结2023/3/1

每日总结2023/3/1

时间:2023-03-01 22:12:37浏览次数:43  
标签:总结 Toast String 每日 private 2023 import android id

今天学习了Android Studio

对于昨日的错误找到了对应的解决方案

没有在前面设置时间监听器,所以无法触发R.id事件

 

今日学习了链接本地数据库,

成果

 

 

 对于图一,代码如下

xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:background="#f3f3f3"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="180dp"
        android:text="@string/app_name"
        android:textColor="@color/black"
        android:textSize="20dp"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:padding="20dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_main_background"
            android:padding="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="用户名 : "
                android:textColor="@color/black"
                android:textSize="18dp" />

            <EditText
                android:id="@+id/main_ed_zhang"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:imeOptions="actionSearch"
                android:maxLength="10"
                android:hint="请输入用户名/ID"
                android:maxLines="1"
                android:singleLine="true" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="@drawable/ic_main_background"
            android:padding="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密    码 : "
                android:textColor="@color/black"
                android:textSize="18dp" />

            <EditText
                android:id="@+id/main_ed_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:imeOptions="actionSearch"
                android:inputType="textPassword"
                android:maxLength="10"
                android:hint="请输入密码"
                android:maxLines="1"
                android:singleLine="true"
                android:textColorHint="#bcbcbc" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:padding="5dp">

        <Button
            android:id="@+id/main_bu_deng"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="登录"
            android:onClick="onClick"
            android:textStyle="bold" />

        <Button
            android:id="@+id/main_bu_zhu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:text="注册"
            android:onClick="onClick"
            android:textStyle="bold" />
    </LinearLayout>

</LinearLayout>

Java文件

package com.example.meiri;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.meiri.db.DBOpenHelper;
import com.example.meiri.db.User;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private DBOpenHelper mDBOpenHelper;
    private EditText mEtRegisteractivityzhang;
    private EditText mEtRegisteractivitypassword;
    private Button mBtRegisteractivitydeng;
    private Button mBtRegisteractivityzhu;

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

        mDBOpenHelper = new DBOpenHelper(this);
    }
    private void initView() {
        // 初始化控件
        mEtRegisteractivityzhang = findViewById(R.id.main_ed_zhang);
        mEtRegisteractivitypassword = findViewById(R.id.main_ed_password);
        mBtRegisteractivitydeng = findViewById(R.id.main_bu_deng);
        mBtRegisteractivityzhu = findViewById(R.id.main_bu_zhu);

        // 设置点击事件监听器
        mBtRegisteractivitydeng.setOnClickListener(this::onClick);
        mBtRegisteractivityzhu.setOnClickListener(this::onClick);

    }

    public void onClick(View view) {
        switch (view.getId()) {
            // 跳转到注册界面
            case R.id.main_bu_zhu:
                startActivity(new Intent(this, RegisterActivity.class));
                finish();
                break;

            case R.id.main_bu_deng:
                String id = mEtRegisteractivityzhang.getText().toString().trim();
                String password = mEtRegisteractivitypassword.getText().toString().trim();

                if (!TextUtils.isEmpty(id) && !TextUtils.isEmpty(password)) {
                        ArrayList<User> data = mDBOpenHelper.getAllData();
                        boolean match = false;
                        for (int i = 0; i < data.size(); i++) {
                            User user = data.get(i);
                            if (id.equals(user.getName()) && password.equals(user.getPassword())/*&&phoneCode.equals(realCode)*/) {
                                match = true;
                                break;
                            } else {
                                match = false;
                            }
                        }

                        if (match) {
                            Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(this,DakaActivity.class);
                            startActivity(intent);
                            finish();//销毁此Activity
                        } else {
                            Toast.makeText(this, "用户名或密码不正确,请重新输入", Toast.LENGTH_SHORT).show();
                        }
                } else {
                    Toast.makeText(this, "请输入你的用户名或密码", Toast.LENGTH_SHORT).show();
                }


                break;
        }


    }
}

 

对于图二,代码如下;

xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f3f3f3"
    android:orientation="vertical"
    tools:context=".RegisterActivity">

    <ImageView
        android:id="@+id/iv_registeractivity_back"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:src="@mipmap/back"
        android:layout_marginTop="15dp"
        android:clickable="true"
        android:onClick="onClick" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="注册"
        android:gravity="center"
        android:textStyle="bold"
        android:textSize="30dp"
        android:textColor="@color/black"
        android:layout_marginTop="20dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="18dp"
            android:layout_marginRight="18dp"
            android:background="@drawable/ic_main_background"
            android:gravity="center"
            android:orientation="vertical"
            android:paddingLeft="43dp"
            android:paddingRight="31dp">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="学号"
                    android:textSize="16dp" />

                <EditText
                    android:id="@+id/et_registeractivity_id"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="20dp"
                    android:background="@null"
                    android:maxLength="8"
                    android:maxLines="1"
                    android:imeOptions="actionSearch"
                    android:singleLine="true"
                    android:hint="请输入学号"
                    android:textColor="#000000"
                    android:textColorHint="#bcbcbc"
                    android:textSize="18sp" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="23dp"
                android:layout_marginBottom="23dp"
                android:background="#f3f3f3" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="用户名"
                    android:textSize="16dp" />

                <EditText
                    android:id="@+id/et_registeractivity_username"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:background="@null"
                    android:hint="请输入用户名/姓名"
                    android:textColor="@color/black"
                    android:imeOptions="actionSearch"
                    android:singleLine="true"
                    android:textColorHint="#bcbcbc"
                    android:textSize="18sp" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="23dp"
                android:layout_marginBottom="23dp"
                android:background="#f3f3f3" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="手机号"
                    android:textSize="16dp"/>

                <EditText
                    android:id="@+id/et_registeractivity_phone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:background="@null"
                    android:imeOptions="actionSearch"
                    android:singleLine="true"
                    android:hint="请输入手机号码"
                    android:textColor="@color/black"
                    android:textColorHint="#bcbcbc"
                    android:textSize="18sp"
                    tools:ignore="TextFields" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="23dp"
                android:layout_marginBottom="23dp"
                android:background="#f3f3f3" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/classes"
                    android:textSize="16dp"/>

                <EditText
                    android:id="@+id/et_registeractivity_classes"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:background="@null"
                    android:imeOptions="actionSearch"
                    android:singleLine="true"
                    android:hint="请输入所在班级"
                    android:textColor="@color/black"
                    android:textColorHint="#bcbcbc"
                    android:textSize="18sp" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="23dp"
                android:layout_marginBottom="23dp"
                android:background="#f3f3f3" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="密码"
                    android:textSize="16dp"/>

                <EditText
                    android:id="@+id/et_registeractivity_password"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:background="@null"
                    android:hint="请输入密码"
                    android:imeOptions="actionSearch"
                    android:singleLine="true"
                    android:inputType="textPassword"
                    android:textColor="@color/black"
                    android:textColorHint="#bcbcbc"
                    android:textSize="18sp" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="23dp"
                android:layout_marginBottom="23dp"
                android:background="#f3f3f3" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginRight="15dp"
                android:orientation="horizontal">
                
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <EditText
                        android:id="@+id/et_registeractivity_phoneCodes"
                        android:layout_width="196dp"
                        android:layout_height="50dp"
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="10dp"
                        android:layout_weight="3"
                        android:hint="请输入验证码"
                        android:textColor="#000000"
                        android:textColorHint="#bcbcbc" />

                    <ImageView
                        android:id="@+id/iv_registeractivity_showCode"
                        android:layout_width="95dp"
                        android:layout_height="63dp"
                        android:layout_marginTop="-10dp"
                        android:layout_weight="1.5"
                        android:clickable="true"
                        android:onClick="onClick" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

        <Button
            android:id="@+id/bt_registeractivity_register"
            android:layout_width="match_parent"
            android:layout_height="55dp"
            android:layout_marginLeft="18dp"
            android:layout_marginTop="40dp"
            android:layout_marginRight="18dp"
            android:text="注册"
            android:textColor="@color/white"
            android:textSize="24sp" />
    </LinearLayout>

</RelativeLayout>

 

Java文件

package com.example.meiri;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import com.example.meiri.db.DBOpenHelper;
import com.example.meiri.util.Code;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {

    private String realCode;
    private DBOpenHelper mDBOpenHelper;
    private EditText mEtRegisteractivityID; //ID、学号
    private Button mBtRegisteractivityRegister;//注册
    private ImageView mIvRegisteractivityBack;//返回
    private EditText mEtRegisteractivityUsername;   //姓名
    private EditText mEtRegisteractivityPhone;  //手机号
    private EditText mEtRegisteractivityclasses;    //班级
    private EditText mEtRegisteractivitypassword;   //密码
    private EditText mEtRegisteractivityPhonecodes;//用户输入的验证码
    private ImageView mIvRegisteractivityShowcode;  //验证码图片

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

        initView();

        mDBOpenHelper = new DBOpenHelper(this);

        //将验证码用图片的形式显示出来
        mIvRegisteractivityShowcode.setImageBitmap(Code.getInstance().createBitmap());
        realCode = Code.getInstance().getCode().toLowerCase();
    }

    private void initView() {
        mEtRegisteractivityID = findViewById(R.id.et_registeractivity_id);
        mEtRegisteractivityPhone = findViewById(R.id.et_registeractivity_phone);
        mEtRegisteractivityclasses = findViewById(R.id.et_registeractivity_classes);
        mBtRegisteractivityRegister = findViewById(R.id.bt_registeractivity_register);
        mIvRegisteractivityBack = findViewById(R.id.iv_registeractivity_back);
        mEtRegisteractivityUsername = findViewById(R.id.et_registeractivity_username);
        mEtRegisteractivityPhonecodes = findViewById(R.id.et_registeractivity_phoneCodes);
        mEtRegisteractivitypassword = findViewById(R.id.et_registeractivity_password);
        mIvRegisteractivityShowcode = findViewById(R.id.iv_registeractivity_showCode);


        mIvRegisteractivityBack.setOnClickListener(this);
        mIvRegisteractivityShowcode.setOnClickListener(this);
        mBtRegisteractivityRegister.setOnClickListener(this);
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_registeractivity_back: //返回登录页面
                Intent intent1 = new Intent(this, MainActivity.class);
                startActivity(intent1);
                finish();
                break;
            case R.id.iv_registeractivity_showCode:    //改变随机验证码的生成
                mIvRegisteractivityShowcode.setImageBitmap(Code.getInstance().createBitmap());
                realCode = Code.getInstance().getCode().toLowerCase();
                break;
//            private String ID;      //用户ID(学号)
//            private String name;       //用户名,姓名
//            private String phone;      //手机号码
//            private String classes;  //用户单位,班级
//            private String password;    //  用户密码
            case R.id.bt_registeractivity_register:    //注册按钮
                //获取用户输入的用户名、密码、验证码
                String ID = mEtRegisteractivityID.getText().toString().trim();
                String username = mEtRegisteractivityUsername.getText().toString().trim();
                String phone = mEtRegisteractivityPhone.getText().toString().trim();
                String classes = mEtRegisteractivityclasses.getText().toString().trim();
                String password = mEtRegisteractivitypassword.getText().toString().trim();
                String phoneCode = mEtRegisteractivityPhonecodes.getText().toString().toLowerCase();
                //注册验证
                if (!TextUtils.isEmpty(ID) && !TextUtils.isEmpty(username)
                        && !TextUtils.isEmpty(phone) && !TextUtils.isEmpty(classes)
                        && !TextUtils.isEmpty(password) && !TextUtils.isEmpty(phoneCode)) {
                    if (phoneCode.equals(realCode)) {
                        //将用户名和密码加入到数据库中
                        mDBOpenHelper.add(ID,username, phone,classes,password);
                        Intent intent2 = new Intent(this, MainActivity.class);
                        startActivity(intent2);
                        finish();
                        Toast.makeText(this, "验证通过,注册成功", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "验证码错误,注册失败", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(this, "未完善信息,注册失败", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}

 

标签:总结,Toast,String,每日,private,2023,import,android,id
From: https://www.cnblogs.com/JJTyyds/p/17170064.html

相关文章

  • 每日总结 3.1
    今天学习了登陆界面的操作。学习了连接数据库的用户登录:packagecom.example.clock.db;importandroid.content.Context;importandroid.database.Cursor;import......
  • 2023.3.1每日总结
    packagecom.example.myapplication;importandroidx.appcompat.app.AppCompatActivity;importandroid.content.ContentValues;importandroid.database.sqlite.S......
  • 社招中级前端笔试面试题总结
    typeofnull的结果是什么,为什么?typeofnull的结果是Object。在JavaScript第一个版本中,所有值都存储在32位的单元中,每个单元包含一个小的类型标签(1-3bits)以及......
  • 尚硅谷_每日一考_445
    4451.画图说明线程的生命周期,以及各状态切换使用到的方法等由于某个方法的调用导致状态的变化https://blog.csdn.net/pange1991/article/details/538606512.同步代码共......
  • 3月01日课后总结
    3/01课后总结装饰器装饰器简易版本defouter(func_name):#func_name=indexdefget_time():#1.在函数执行之前,要记录一下此时的时间sta......
  • day01(2023.3.1)
    1、了解了Java运行机制jdk和jre和jvm的区别 2、下载安装jdk然后配置环境变量 并验证是否成功(1)百度收搜Jdk8(推荐),找到下载地址。(2)同意协议,下载电脑对应的版本。......
  • 2023/2/27每日总结
    以下为今日课上所写代码packageText;importjava.io.*;importjava.util.ArrayList;importjava.util.List;importjava.util.Scanner;/*关于文件导入并找出最长的接龙单......
  • C语言员工信息管理系统[2023-03-01]
    C语言员工信息管理系统[2023-03-01]物联网工程专业程序设计基础课程设计员工信息管理系统学院(系):信息与通信工程学院专业:物联网工程学生姓名:学......
  • 2023.3.1AcWing蓝桥杯集训·每日一题
    今日的知识点为\(BFS\)(广度优先搜素)。\(BFS\)简要介绍下\(BFS\)算法。首先,\(BFS\)算法适用于边权为\(1\)的图论问题。\(BFS\)算法的解题思路也比较固定。确定......
  • SRTP_Log_20230301
    WorkingContent:1.第一个是参数1,第二个是噪声1,第三个是参数2,第四个是噪声2如果没加噪声(以下情况),所以照理来说噪声1和噪声2的量级应该分别比参数1和参数2小得多,现在看......