99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

Android中怎么利用MVP實現登錄注冊功能-創新互聯

這篇文章給大家介紹Android中怎么利用MVP實現登錄注冊功能,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

成都創新互聯公司-專業網站定制、快速模板網站建設、高性價比烏蘇網站開發、企業建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式烏蘇網站制作公司更省心,省錢,快速模板網站建設找我們,業務覆蓋烏蘇地區。費用合理售后完善,10年實體公司更值得信賴。

model包:

import com.bwei.mvps.bean.UserBean;



public interface IUserModel {
 void setFirstName(String firstName);

 void setLastName(String lastName);

 String getFirstName();

 String getLastName();

 //根據id獲取對象
 UserBean load(int id);
}
import android.util.Log;

import com.bwei.mvps.bean.UserBean;



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) {
 //查詢數據庫或聯網獲取數據
 Log.i("fff", id + "");

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

View包

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;


public class UserPresenter {

 private UserView userview;
 private final IUserModel iUserModel;

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

 }

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

 }

 //查詢數據
 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://保存數據
  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();
 }
}

關于Android中怎么利用MVP實現登錄注冊功能就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

本文名稱:Android中怎么利用MVP實現登錄注冊功能-創新互聯
網站URL:http://www.yijiale78.com/article0/pceoo.html

成都網站建設公司_創新互聯,為您提供網站營銷電子商務網頁設計公司微信公眾號品牌網站制作做網站

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都做網站