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.
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); } }
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)); } }
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
1 komentar:
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?
Posting Komentar