MVP接口回调登录
来源:互联网 发布:大津算法 opencv 编辑:程序博客网 时间:2024/06/10 20:24
权限
<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
xml布局
<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:orientation="vertical" tools:context="com.bwie.asus.login.MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="60dp" android:text="用户名" android:textSize="20sp" /> <EditText android:id="@+id/username" android:layout_width="200dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="60dp" android:text="密 码" android:textSize="20sp" /> <EditText android:id="@+id/password" android:layout_width="200dp" android:layout_height="wrap_content" /> </LinearLayout> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="30dp" android:text="登录" /></LinearLayout>
MainActivity类
<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:orientation="vertical" tools:context="com.bwie.asus.login.MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="60dp" android:text="用户名" android:textSize="20sp" /> <EditText android:id="@+id/username" android:layout_width="200dp" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="60dp" android:text="密 码" android:textSize="20sp" /> <EditText android:id="@+id/password" android:layout_width="200dp" android:layout_height="wrap_content" /> </LinearLayout> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="30dp" android:text="登录" /></LinearLayout>
Login类
package com.bwie.asus.login;/** * Created by ASUS on 2017/10/8. */public interface Login { public void name(); public void pwd(); public void loginsuccess(String result);}
Model类
package com.bwie.asus.login;import java.io.IOException;import okhttp3.Call;import okhttp3.Callback;import okhttp3.OkHttpClient;import okhttp3.Request;import okhttp3.Response;/** * Created by ASUS on 2017/10/8. */public class Model { interface ModelList{ public void loginsuccess(String result); } public void setLogin(String username, String password, final ModelList modelList){ OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url("http://qhb.2dyt.com/Bwei/login?username=muhanxi&password=111&postkey=1503d").build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { String result = response.body().string(); modelList.loginsuccess(result); } }); }}
Presenter类
package com.bwie.asus.login;import android.text.TextUtils;/** * Created by ASUS on 2017/10/8. */public class Presenter { private Login login; private Model model; public Presenter(Login login) { this.login = login; this.model = new Model(); } public void setLogin(String username,String password){ if (TextUtils.isEmpty(username)){ login.name(); return; } if (TextUtils.isEmpty(password)){ login.pwd(); return; } model.setLogin(username, password, new Model.ModelList() { @Override public void loginsuccess(String result) { login.loginsuccess(result); } }); }}
阅读全文
0 0
- MVP接口回调登录
- MVP接口登录注册
- MVP接口回调注册
- Mvp登录
- mvp登录
- MVP登录
- 请求网络接口_注册登录之MVP模式
- MVP入门,接口回调new接口和implement实现,防止内存泄露解绑
- android mvp实现登录
- MVP 实现登录注册
- MVP的简单登录
- 登录注册mvp模式
- MVP注册登录
- MVP 登录注册
- MVP架构,登录页面
- MVP注册登录
- MVP的简单登录
- MVP之登录
- 类装载器实现Java虚拟机安全(三)
- 【C++】总览
- Bootstrap fileinput.js,最好用的文件上传组件
- C++中为何每次使用strcpy()总会出现警告?
- MVC——ViewModel的数据验证
- MVP接口回调登录
- Java虚拟机安全性-class文件检验器,看完请务必收藏!
- FullCalendar中设置默认日期
- Linux C编程第三章的10个问题以及解决方案
- C++ this
- 2017 Fall SoftwareEngineering Learning (3)
- 计算圆面积、周长和三角形面积、周长
- Http请求网络数据
- LeetCode[518]Coin Change 2(Java)