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

每日总结2023/3/3

时间:2023-03-03 18:12:10浏览次数:45  
标签:总结 name 每日 2023 import android password public String

今天学习了安卓连接sqlite并且进行登录注册操作

main.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"
    tools:context=".MainActivity"
    android:orientation="vertical"
    >
    <View
        android:layout_width="match_parent"
        android:layout_height="120dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="账号:"
            android:layout_weight="1"
            android:textSize="30dp"
            android:gravity="center_vertical"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:id="@+id/edname"/>


    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="密码:"
            android:layout_weight="1"
            android:textSize="30dp"
            android:gravity="center_vertical"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:id="@+id/edpassword"/>



    </LinearLayout>
    <Button
        android:layout_width="160dp"
        android:layout_height="80dp"
        android:text="登录"
        android:textSize="27dp"
        android:id="@+id/login"
        android:layout_gravity="center"/>

    <Button
        android:layout_width="160dp"
        android:layout_height="80dp"
        android:text="注册"
        android:textSize="27dp"
        android:id="@+id/register"
        android:layout_gravity="center"/>

register.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"
    tools:context=".register"
    android:orientation="vertical"
    >
    <View
        android:layout_width="match_parent"
        android:layout_height="120dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="账号:"
            android:layout_weight="1"
            android:textSize="30dp"
            android:gravity="center_vertical"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:id="@+id/edname1"/>


    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="密码:"
            android:layout_weight="1"
            android:textSize="30dp"
            android:gravity="center_vertical"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:id="@+id/edpassword1"/>



    </LinearLayout>
    <Button
        android:layout_width="160dp"
        android:layout_height="80dp"
        android:text="注册"
        android:textSize="27dp"
        android:id="@+id/register1"
        android:layout_gravity="center"
        android:onClick="zhuche"
        />
</LinearLayout>

第二跳转页面good.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.a86191.mylogin.good">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="登陆成功"
        android:textSize="100dp"/>

</android.support.constraint.ConstraintLayout>

user的java

package com.example.a86191.mylogin.javabean;

/**
 * Created by 86191 on 2023/3/2.
 */
public class User {
    private String name;
    private String password;

    public User() {
    }

    public User(String name, String password) {
        this.name = name;
        this.password = password;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return password
     */
    public String getPassword() {
        return password;
    }

    /**
     * 设置
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    public String toString() {
        return "User{name = " + name + ", password = " + password + "}";
    }
}

good

package com.example.a86191.mylogin;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class good extends AppCompatActivity {

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

MainActivity

package com.example.a86191.mylogin;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.a86191.mylogin.javabean.User;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button login,register;
private EditText name,password;
private MYsqLiteopenhelper mYsqLiteopenhelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mYsqLiteopenhelper=new MYsqLiteopenhelper(this);
        find();
    }
    private void find(){
        login=findViewById(R.id.login);
        register=findViewById(R.id.register);
        name=findViewById(R.id.edname);
        password=findViewById(R.id.edpassword);
        login.setOnClickListener(this);
        register.setOnClickListener(this);
    }
    @Override
    public void onClick(View view){
int id=view.getId();
switch (id){
    case R.id.login:
        String s=name.getText().toString();
        String s1=password.getText().toString();

       Boolean login= mYsqLiteopenhelper.login(s,s1);
       if (login){
           Toast.makeText(this,"登陆成功",Toast.LENGTH_SHORT).show();
           Intent i = new Intent(this,good.class);
           startActivity(i);
       }else{
           Toast.makeText(this,"登陆失败",Toast.LENGTH_SHORT).show();
       }
        break;
    case R.id.register:

        Intent i1=new Intent(this,com.example.a86191.mylogin.register.class);
        startActivity(i1);
        break;
}
    }
}

MYsqLiteopenhelper

package com.example.a86191.mylogin;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.Nullable;

import com.example.a86191.mylogin.javabean.User;

import java.util.ResourceBundle;

/**
 * Created by 86191 on 2023/3/2.
 */

public class MYsqLiteopenhelper extends SQLiteOpenHelper {
    private static final String DB_NAME="MYsqlite.db";


    private static final String create_users="create table users(name varchar(32),password varchar(32))";


    public MYsqLiteopenhelper(@Nullable Context context) {
        super(context, DB_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(create_users);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }

    public long register(User u){
        SQLiteDatabase db = getWritableDatabase();
        ContentValues cv =new ContentValues();
        cv.put("name",u.getName());
        cv.put("password",u.getPassword());
        long users = db.insert("users", null, cv);
        return users;

    }

    public boolean login(String name,String password) {
        SQLiteDatabase db1 = getWritableDatabase();
        boolean result = false;

        Cursor users = db1.query("users", null, "name like ?", new String[]{name}, null, null, null);
        if (users != null) {
            while (users.moveToNext()) {
                String password1 = users.getString(1);
                result = password1.equals(password);
                return result;

            }

        }
        return false;
    }}

register

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.a86191.mylogin.javabean.User;

public class register extends AppCompatActivity {
    private Button register1;
    private EditText name1,password1;
    private MYsqLiteopenhelper mYsqLiteopenhelper1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        mYsqLiteopenhelper1=new MYsqLiteopenhelper(this);
        find();
    }
    public void find(){

        register1=findViewById(R.id.register1);
        name1=findViewById(R.id.edname1);
        password1=findViewById(R.id.edpassword1);


    }


    public void zhuche(View view) {
        String s=name1.getText().toString();
        String s1=password1.getText().toString();
        User u =new User(s,s1);
        long l=mYsqLiteopenhelper1.register(u);
        if(l !=-1){
            Toast.makeText(this,"注册成功",Toast.LENGTH_SHORT).show();
            Intent i3=new Intent(this,MainActivity.class);
            startActivity(i3);
        }else{
            Toast.makeText(this,"注册失败",Toast.LENGTH_SHORT).show();
        }
    }
}

 

标签:总结,name,每日,2023,import,android,password,public,String
From: https://www.cnblogs.com/azwz/p/17176596.html

相关文章

  • 【总结】2023-03-01 Count Interval
    CountInterval题意给定\(n\)个数字\(a_1,a_2\ldotsa_n\)和一个整数\(k\),求有多少个非空子段之和为\(k\)。也就是问有多少对数\((l,r)(1\leqslantl\leqsla......
  • 实验一 20230302
    #include<stdio.h>intmain(){printf("0\n");printf("<H>\n");printf("II\n");return0;} #include<stdio.h>intmai......
  • Python全栈面试题及知识点总结
    Python全栈面试题Python全栈阶段总结:https://github.com/HkwJsxl/PythonFullStack/tree/master/NotesPython基础基础逻辑运算v2="wupeiqi"and"alex"#第一步:将a......
  • 规则平台 项目结构梳理 功能框架细节总结
    主要功能:策略链路-规则-配置后台管理系统:权限团队策略规则管理等其他功能;主要业务框架业务概念:策略-规则;结构概念:抽象为链路-节点;aop拦截器的应用单机缓存的应用......
  • Go组件库总结之协程睡眠唤醒
    本篇文章我们用Go封装一个利用gopark和goready实现协程睡眠唤醒的库。文章参考自:https://github.com/brewlin/net-protocol1.gopark和goready的声明//go:linknamegopark......
  • 2022到2023
    2022年到2023年,工作内容发生了很大变化。原来在字节主要做iOS平台上的业务开发,使用Swift语言。后面新的工作内容主要做IoT相关,不再局限在移动端,而是围绕整个IoT系统。从i......
  • 2023-03-03 js map 双重嵌套
    恩。。其实也没啥要记录的,记住关键一点就是必须要有return,不管是几重,比如:arr.map((item,index)=>{  return(    item.arr2.map((item2,index2)=>{......
  • IDEA常用快捷键总结
    IDEA常用快捷键总结前言IDEA中提供了很多快捷键,点击File-->Settings-->keymap便可进入看到IDEA提供的快捷键。我们也可以搜索和自定义所有快捷键,下面给出的是IDE......
  • 总结一下搭建个人网站《曼云古籍在线识别》的完整流程
    继2年前开发出一个标注工具PaddleOCRLabel之后,我就开始炼丹之旅,全面allin人工智能,历时一年,终于炼成了第一颗“丹”——针对于古籍的ocr识别模型。经过400万图片的验证,目前......
  • 代码随想录算法训练营第四天 | 24. 两两交换链表中的节点、19.删除链表的倒数第N个节
    24.两两交换链表中的节点-力扣(LeetCode)给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交......