Iview接口
package com.xinzhengwei.denglu.view; /** * Created by 辛政维 on 2018/1/12. */ public interface Iviwe { String getMobile(); String getPassword(); void jumpActivity(); void shouError(); }
MainActivity主页面
package com.xinzhengwei.denglu.view; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.xinzhengwei.denglu.R; import com.xinzhengwei.denglu.model.ImodelImp; import com.xinzhengwei.denglu.presenter.Presenter; import com.xinzhengwei.denglu.presenter.PresenterImp; public class MainActivity extends AppCompatActivity implements Iviwe, View.OnClickListener { private EditText mobile; private EditText password; private Button login; private Button reg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { mobile = findViewById(R.id.mobile); password = findViewById(R.id.password); login = findViewById(R.id.login); reg = findViewById(R.id.reg); login.setOnClickListener(this); reg.setOnClickListener(this); } @Override public String getMobile() { return mobile.getText().toString(); } @Override public String getPassword() { return password.getText().toString(); } @Override public void jumpActivity() { startActivity(new Intent(MainActivity.this,ContActivity.class)); } @Override public void shouError() { Toast.makeText(this, "登录失败,请注册", Toast.LENGTH_SHORT).show(); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.login: PresenterImp presenterImp = new PresenterImp(); presenterImp.login(new ImodelImp(),MainActivity.this); break; case R.id.reg: startActivity(new Intent(MainActivity.this,RegActivity.class)); break; } } } 主页面布局<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.xinzhengwei.denglu.view.MainActivity"> <EditText android:id="@+id/mobile" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal"> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录"/> <Button android:id="@+id/reg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注册"/> </LinearLayout> </LinearLayout>RegActivity注册页面跳转页面package com.xinzhengwei.denglu.view; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.xinzhengwei.denglu.R; import com.xinzhengwei.denglu.model.ImodelImp; import com.xinzhengwei.denglu.presenter.PresenterImp; public class RegActivity extends AppCompatActivity implements Iviwe, View.OnClickListener { private EditText mobile; private EditText password; private Button reg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_reg); initView(); } private void initView() { mobile = findViewById(R.id.mobile); password = findViewById(R.id.password); reg = findViewById(R.id.reg); reg.setOnClickListener(this); } @Override public String getMobile() { return mobile.getText().toString(); } @Override public String getPassword() { return password.getText().toString(); } @Override public void jumpActivity() { startActivity(new Intent(RegActivity.this,MainActivity.class)); } @Override public void shouError() { Toast.makeText(this, "注册失败,请重新注册", Toast.LENGTH_SHORT).show(); } @Override public void onClick(View view) { PresenterImp presenterImp = new PresenterImp(); presenterImp.reg(new ImodelImp(),this); } }
注册页面布局<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.xinzhengwei.denglu.view.RegActivity"> <EditText android:id="@+id/mobile" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal"> <Button android:id="@+id/reg" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册"/> </LinearLayout> </LinearLayout>package com.xinzhengwei.denglu.view; import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import com.xinzhengwei.denglu.R; /** * Created by 辛政维 on 2018/1/12. */ public class ContActivity extends Activity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cont_mian); } }
布局<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录成功"/> </LinearLayout>