Modelo

// Model public class User { private String fullName; public void setFullName(String fullName) { this.fullName = fullName; } @Override public String toString() { return "FullName : " + fullName + "\n"; } } // Presenter public class MainPresenter { User user; View view; public MainPresenter(View view) { this.view = view; user = new User(); } public void updateFullName(String fullName) { user.setFullName(fullName); view.updateUserInfoTextView(user.toString()); } public interface View { void updateUserInfoTextView(String info); } } public class MainActivity extends AppCompatActivity implements MainPresenter.View { MainPresenter mainPresenter; TextView userInfoTextView; EditText fullName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mainPresenter = new MainPresenter(this); userInfoTextView = (TextView) findViewById(R.id.userInfo); fullName = (EditText) findViewById(R.id.fullName); email = (EditText) findViewById(R.id.email); fullName.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { mainPresenter.updateFullName(s.toString()); } @Override public void afterTextChanged(Editable s) { } }); @Override public void updateUserInfoTextView(String info) { userInfoTextView.setText(info); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.