Langsung ke konten utama

[DIY Tutorial] Implement MVP on Android ~ DroidUMM

This is a tutorial on applying MVP android from the previous material. I took this article from http://jamespeckham.com following article is very simple to be implemented so you need to do the implementation.

Now you make your android project. finish creating a project android, created three packages.


create a class with the name AskNameView.java used as a Main Activity or up to you if you have any other name that you created by the wizard



package com.jpeckham.examples;

import com.jpeckham.examples.presenters.AskNamePresenter;
import com.jpeckham.examples.views.IAskNameView;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class AskNameView extends Activity implements IAskNameView {
    /** Called when the activity is first created. */
 AskNamePresenter _presenter;
 
 public AskNameView(){
  _presenter = new AskNamePresenter(this);
 }
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

 public void setDisplayedText(String text) {
  getShownLabel().setText(text);
 }
 
 public void submitClicked(View widget) {
  _presenter.EnterNameAndAge(getNameField().getText().toString(), 
    Integer.parseInt(getAgeField().getText().toString()));
 }
 
 private EditText getNameField() {
  return (EditText) findViewById(R.id.name);
 }
 private EditText getAgeField(){
  return (EditText) findViewById(R.id.age);
 }
 private TextView getShownLabel(){
  return (TextView) findViewById(R.id.shown);
 }
}
Next on the package com.jpeckham.examples.presenters, you create a new class with the name AskNamePresenter. This class is used as the presenters of the MVP

package com.jpeckham.examples.presenters;

import com.jpeckham.examples.views.IAskNameView;

public class AskNamePresenter {
 private IAskNameView _view;
 public AskNamePresenter(IAskNameView view){
  _view = view;
 }
 public void EnterNameAndAge(String name, int age) {
  _view.setDisplayedText(String.format("%s is %d years old",name,age));
 }
}
On the package you create interfaces IAskNameView com.jpeckham.examples.views. purpose of this interface is to make the defining view of the application later. and will be implemented in the main activity
package com.jpeckham.examples.views;

public interface IAskNameView {
 public void setDisplayedText(String text);
}


And Your Layout modif like this :





android programming,programming for android,programming android apps,mvp pattern,design patterns mvp instructor led training class

Komentar

  1. This tutorial is either incomplete (seems to end rather abruptly), or its just plain wrong.

    The last part, with the view XML, it's completely incorrect, you have formatting issues, typos, and nested view elements which are all invalid.

    Was this an attempt to rip the post from James Peckham?

    BalasHapus

Posting Komentar

Postingan populer dari blog ini

[Concept] Model View Present (MVP) Pattern for Architecture Android~ DroidUMM

 Model-View-Presenter (MVP) is an architecture pattern for the presentation layer of software applications. The pattern was originally developed at Taligent in 1990s and first was implemented in C++ and Java. In MVP, the View and the Model are neatly separated and the View exposes a contract through which the Presenter access the portion of View that is dependent on the rest of the system.  [Next Article Implement MVP on Android] The Model is the component which preserves data, state and business logic; it just exposes a group of service interfaces to Presenter and hides the internal details. The View is the user interface, it receives user’s action and contract to Presenter to achieve user’s need, and then the View responds user by result information. The Presenter sits in between the View and the Model; it receives input from the View and passes commands down to the Model. It then gets result and updates the View trough the contracted View interface.

WhatsAppSniffer Hack WhatsApp

Who uses WhatsApp Messenger? From The look of the  Play Store listing , a  damn lot  of people. Considering it's so popular, it's probably a pretty secure app, right? Think again. WhatsApp actually sends all chats in  plaintext , so anyone on the same Wi-Fi network can easily pull your entire conversation - including pictures and videos - straight out of the air. And now, that process is even easier than ever thanks to a new app called  WhatsAppSniffer . It's basically just a packet sniffer, but it makes the process of pulling WhatsApp chats out of the sky stupid-easy, and that's never a good thing. You might as well just shout your private conversations across the room.