亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android封裝MVP實現(xiàn)登錄注冊功能

 更新時間:2017年11月10日 08:50:45   作者:贏le  
這篇文章主要為大家詳細介紹了Android封裝MVP實現(xiàn)登錄注冊功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android封裝MVP實現(xiàn)登錄注冊功能,供大家參考,具體內(nèi)容如下

model包:

import com.bwei.mvps.bean.UserBean;

/**
 * 1. 類的用途
 * 2. @author forever
 * 3. @date 2017/9/1 16:00
 */

public interface IUserModel {
 void setFirstName(String firstName);

 void setLastName(String lastName);

 String getFirstName();

 String getLastName();

 //根據(jù)id獲取對象
 UserBean load(int id);
}

import android.util.Log;

import com.bwei.mvps.bean.UserBean;

/**
 * 1. 類的用途
 * 2. @author forever
 * 3. @date 2017/9/1 16:04
 */

public class UserModel implements IUserModel {
 @Override
 public void setFirstName(String firstName) {
 Log.i("xxx", firstName);
 }

 @Override
 public void setLastName(String lastName) {
 Log.i("xxx", lastName);

 }

 @Override
 public String getFirstName() {
 return null;
 }

 @Override
 public String getLastName() {
 return null;
 }

 @Override
 public UserBean load(int id) {
 //查詢數(shù)據(jù)庫或聯(lián)網(wǎng)獲取數(shù)據(jù)
 Log.i("fff", id + "");

 return new UserBean("張", "三");
 }
}

View包

/**
 * 1. 類的用途
 * 2. @author forever
 * 3. @date 2017/9/1 15:53
 */

public interface UserView {
 void setFirstName(String firstName);

 void setLastName(String lastName);

 int getId();

 String getFirstName();

 String getLastName();
}

presenter包:

import android.util.Log;

import com.bwei.mvps.MainActivity;
import com.bwei.mvps.bean.UserBean;
import com.bwei.mvps.model.IUserModel;
import com.bwei.mvps.model.UserModel;
import com.bwei.mvps.view.UserView;

/**
 * 1. 類的用途
 * 2. @author forever
 * 3. @date 2017/9/1 16:05
 */

public class UserPresenter {

 private UserView userview;
 private final IUserModel iUserModel;

 public UserPresenter(UserView userview) {
 this.userview = userview;
 iUserModel = new UserModel();

 }

 //保存數(shù)據(jù)
 public void saveUser(int id, String firstName, String lastName) {
 UserBean userBean = iUserModel.load(id);
 Log.i("sss", "id:" + id + ",firstName:" + firstName + ",lastName:" + lastName);

 }

 //查詢數(shù)據(jù)
 public void find(int id) {
 UserBean userBean = iUserModel.load(id);
 String firstName = userBean.getFirstName();
 String lastName = userBean.getLastName();
 userview.setFirstName(firstName);
 userview.setLastName(lastName);

 Log.i("aaa", "id:" + id + ",firstName:" + firstName + ",lastName:" + lastName);

 }
}

XML

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

 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">

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

 <TextView
  android:layout_width="70dp"
  android:layout_height="wrap_content"
  android:text="ID"/>

 <EditText
  android:id="@+id/et_id"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_weight="1"/>
 </LinearLayout>

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

 <TextView
  android:layout_width="70dp"
  android:layout_height="wrap_content"
  android:text="FirstName"/>

 <EditText
  android:id="@+id/et_first_name"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_weight="1"/>
 </LinearLayout>

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

 <TextView
  android:layout_width="70dp"
  android:layout_height="wrap_content"
  android:text="LastName"/>

 <EditText
  android:id="@+id/et_last_name"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_weight="1"/>
 </LinearLayout>

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

 <Button
  android:id="@+id/bt_register"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:text="注冊"/>

 <Button
  android:id="@+id/bt_login"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:text="登錄"/>
 </LinearLayout>
</LinearLayout>

Mactivity

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

import com.bwei.mvps.presenter.UserPresenter;
import com.bwei.mvps.view.UserView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, UserView {

 private EditText et_id;
 private EditText et_first_name;
 private EditText et_last_name;
 private Button bt_login;
 private Button bt_register;
 private UserPresenter userPresenter;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 //找控件
 et_id = (EditText) findViewById(R.id.et_id);
 et_first_name = (EditText) findViewById(R.id.et_first_name);
 et_last_name = (EditText) findViewById(R.id.et_last_name);
 bt_login = (Button) findViewById(R.id.bt_login);
 bt_register = (Button) findViewById(R.id.bt_register);
 bt_login.setOnClickListener(this);
 bt_register.setOnClickListener(this);
 //聲明UserPresenter
 userPresenter = new UserPresenter(this);

 }

 @Override
 public void onClick(View view) {
 switch (view.getId()) {
  case R.id.bt_register://保存數(shù)據(jù)
  userPresenter.saveUser(getId(), getFirstName(), getLastName());
  break;
  case R.id.bt_login:
  userPresenter.find(getId());
  break;
 }
 }

 @Override
 public void setFirstName(String firstName) {
 et_first_name.setText(firstName);
 }

 @Override
 public void setLastName(String lastName) {
 et_last_name.setText(lastName);
 }

 @Override
 public int getId() {
 return new Integer(et_id.getText().toString());
 }

 @Override
 public String getFirstName() {
 return et_first_name.getText().toString();
 }

 @Override
 public String getLastName() {
 return et_last_name.getText().toString();
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • ViewPager實現(xiàn)圖片切換效果

    ViewPager實現(xiàn)圖片切換效果

    這篇文章主要為大家詳細介紹了ViewPager實現(xiàn)圖片切換效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-09-09
  • Android自定義TextView實現(xiàn)drawableLeft內(nèi)容居中

    Android自定義TextView實現(xiàn)drawableLeft內(nèi)容居中

    這篇文章主要介紹了Android自定義TextView實現(xiàn)drawableLeft內(nèi)容居中的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • Android保持屏幕常亮喚醒狀態(tài)的方法

    Android保持屏幕常亮喚醒狀態(tài)的方法

    這篇文章主要介紹了Android保持屏幕常亮喚醒狀態(tài)的方法,實例分析了Android權(quán)限控制及屏幕狀態(tài)操作的相關(guān)實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-10-10
  • Android中實現(xiàn)GPS定位的簡單例子

    Android中實現(xiàn)GPS定位的簡單例子

    這篇文章主要介紹了Android中實現(xiàn)GPS定位的簡單例子,例子邏輯清晰,但相對簡單了些,需要的朋友可以參考下
    2014-07-07
  • android實現(xiàn)狀態(tài)欄添加圖標的函數(shù)實例

    android實現(xiàn)狀態(tài)欄添加圖標的函數(shù)實例

    這篇文章主要介紹了android實現(xiàn)狀態(tài)欄添加圖標的函數(shù),較為詳細的分析了Android狀態(tài)欄添加及刪除圖標的具體實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-10-10
  • Android 點擊屏幕空白處收起輸入法軟鍵盤(手動打開)

    Android 點擊屏幕空白處收起輸入法軟鍵盤(手動打開)

    很多時候,我們在使用應(yīng)用時,會出現(xiàn)輸入法軟鍵盤彈出的問題,通常情況下,我們默認會使用戶點擊返回鍵或者下一步對軟鍵盤進行隱藏。為了更好的體驗,我們可以實現(xiàn)當用戶使用完畢軟鍵盤時。點擊屏幕空白即可實現(xiàn)收起輸入法軟鍵盤
    2016-12-12
  • Android 實現(xiàn)定時任務(wù)的過程詳解

    Android 實現(xiàn)定時任務(wù)的過程詳解

    這篇文章主要介紹了Android 定時任務(wù)過程詳解的相關(guān)資料,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2015-11-11
  • Android實現(xiàn)三段式滑動效果

    Android實現(xiàn)三段式滑動效果

    最近發(fā)現(xiàn)很多app都使用了三段式滑動,比如說高德的首頁和某寶等物流信息都是使用的三段式滑動方式,谷歌其實給了我們很好的2段式滑動,就是BottomSheet,所以這次我也是在這個原理基礎(chǔ)上做了一個小小的修改來實現(xiàn)我們今天想要的效果。
    2021-06-06
  • android使用NotificationListenerService監(jiān)聽通知欄消息

    android使用NotificationListenerService監(jiān)聽通知欄消息

    本篇文章主要介紹了android使用NotificationListenerService監(jiān)聽通知欄消息,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-01-01
  • Android實現(xiàn)紅包雨動畫效果

    Android實現(xiàn)紅包雨動畫效果

    本篇文章主要介紹了Android實現(xiàn)紅包雨動畫效果,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07

最新評論