Friday, 23 February 2018

Android MVP Tutorial From Beginer to Advance Part 2

                                                        Android MVP Part 2

android mvp -tutorial
Android MVP Tutorial
In this Article we are going to make a project with MVP .



If you are not clear with Basic of MVP Pattern, Please read first part of MVP.

Lets start . Make a new Project .

Add a Login
xml :

                                                            DOWNLOAD CODE

activity_login.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:padding="30dp"
    android:layout_height="match_parent">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
       android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Submit"
        />

</LinearLayout>


To achieve MVP Pattern, we need 2 interface and 1 class and 1 Activity .


  • Login Activity
  • LoginView   ->  (Interface )
  • LoginPresenter   -> (Interface ) 
  • LoginPresenterImplemetation  -> ( class)

  • Login Activity implements LoginView .
  • LoginPresenterImplemetation implements LoginPresenter
LoginActivity
    
public class LoginActivity extends AppCompatActivity implements LoginView {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }
}

LoginView
package com.stacklearning.androidmvp.login;
/**
 * Created by jaspreet on 23/2/18.
 */
public interface LoginView {
}

LoginPresenter
package com.stacklearning.androidmvp.login;
/**
 * Created by jaspreet on 23/2/18.
 */
public interface LoginPresenter {
}
LoginPresenterImplemetation
package com.stacklearning.androidmvp.login;
/**
 * Created by jaspreet on 23/2/18.
 */
public class LoginPresenterImplementation implements LoginPresenter {
}


0 comments:

Post a Comment