欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Android中怎么利用MVP實(shí)現(xiàn)登錄注冊(cè)功能

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

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:空間域名、虛擬空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、中陽網(wǎng)站維護(hù)、網(wǎng)站推廣。

model包:

import com.bwei.mvps.bean.UserBean;



public interface IUserModel {
 void setFirstName(String firstName);

 void setLastName(String lastName);

 String getFirstName();

 String getLastName();

 //根據(jù)id獲取對(duì)象
 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) {
 //查詢數(shù)據(jù)庫(kù)或聯(lián)網(wǎng)獲取數(shù)據(jù)
 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();

 }

 //保存數(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="注冊(cè)"/>

 <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();
 }
}

關(guān)于Android中怎么利用MVP實(shí)現(xiàn)登錄注冊(cè)功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

新聞名稱:Android中怎么利用MVP實(shí)現(xiàn)登錄注冊(cè)功能
網(wǎng)站網(wǎng)址:http://www.chinadenli.net/article32/jogcpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)虛擬主機(jī)App開發(fā)商城網(wǎng)站網(wǎng)站改版服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)