In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the Android how to use MVP to achieve login registration related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone in this Android how to use MVP to achieve login registration function article will have a harvest, let's take a look at it.
Model package:
Import com.bwei.mvps.bean.UserBean;public interface IUserModel {void setFirstName (String firstName); void setLastName (String lastName); String getFirstName (); String getLastName (); / / get the object UserBean load (int id) according to 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) {/ / query database or network to obtain data Log.i ("fff", id + "); return new UserBean (" Zhang "," three ");}}
View package
Public interface UserView {void setFirstName (String firstName); void setLastName (String lastName); int getId (); String getFirstName (); String getLastName ();}
Presenter package:
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 ();} / Save data public void saveUser (int id, String firstName, String lastName) {UserBean userBean = iUserModel.load (id) Log.i ("sss", "id:" + id + ", firstName:" + firstName + ", lastName:" + lastName);} / / query data 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
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); / / find controls 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); / / declare UserPresenter userPresenter = new UserPresenter (this);} @ Override public void onClick (View view) {switch (view.getId ()) {case R.id.bt_register:// saves data 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 ();}} this is the end of the article on "how to use MVP to log in and register in Android". Thank you for reading! I believe that everyone has a certain understanding of "how to use MVP to achieve login registration function in Android". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.