MVP 登录 数据库

本文详细介绍了使用MVP模式实现登录功能的步骤,包括依赖配置、登录页面布局、主函数`LoginMainActivity`的代码、`LoginModel`、`LoginPresenter`的实现,以及数据返回到页面的`DataCall`接口、字符串解析工具类`Utils`、SQLite数据库的用户实体类`User`、创建表、DAO层操作和登录成功后的页面处理。
摘要由CSDN通过智能技术生成

1.依赖

implementation ‘com.google.code.gson:gson:2.8.5’

2.主函数的布局(登录页面)

<?xml version="1.0" encoding="utf-8"?>

<EditText
    android:id="@+id/login_phone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="请输入手机号"
    android:padding="10dp" />

<EditText
    android:id="@+id/login_pwd"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="请输入密码" />

<Button
    android:id="@+id/login"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="登录" />

3.登录的主函数代码LoginMainActivity

package com.example.day07mvc;

import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.os.Handler;
import android.os.Message;
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.day07mvc.bean.User;
import com.example.day07mvc.core.DataCall;
import com.example.day07mvc.dao.Dao;
import com.example.day07mvc.http.Utils;
import com.example.day07mvc.model.LoginModel;
import com.example.day07mvc.presenter.LoginPresenter;

public class LoginMainActivity extends AppCompatActivity implements View.OnClickListener,DataCall {
//继承接口DataCall
    private EditText login_phone;
    private EditText login_pwd;
    private Button login;
//    private LoginModel loginModel;
    private LoginPresenter loginPresenter;

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

        Dao dao = new Dao(this);
        Cursor cursor = dao.selete("user&
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值