1. 登录
package yanjupeng20190404.myapplication.mvp.view;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import yanjupeng20190404.myapplication.R;
import yanjupeng20190404.myapplication.cont.Cont;
import yanjupeng20190404.myapplication.mvp.presenter.Presenter;
public class LoginActivity extends AppCompatActivity implements Cont.LoginViewInterface ,View.OnClickListener {
public EditText editText_phone , editText_pwd;
public Button button_login , button_reg;
public Cont.PresenterInterface presenterInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
presenterInterface = new Presenter<>(this);
editText_phone = findViewById(R.id.ed_phone_id);
editText_pwd = findViewById(R.id.ed_pwd_id);
button_login = findViewById(R.id.but_login_id);
button_reg = findViewById(R.id.but_reg_id);
button_reg.setOnClickListener(this);
button_login.setOnClickListener(this);
}
@Override
public void refreshLogin(String info,Object object1,Object object2) {
Toast.makeText(this , info , Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, FragmentActivity.class);
intent.putExtra("name" , object1.toString());
intent.putExtra("img" , object2.toString());
startActivity(intent);
finish();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.but_login_id:
String phone = editText_phone.getText().toString();
String pwd = editText_pwd.getText().toString();
presenterInterface.toLogin(phone , pwd);
break;
case R.id.but_reg_id:
startActivity(new Intent(this , RegActivity.class));
finish();
break;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
presenterInterface.fnish();
presenterInterface = null;
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".mvp.view.LoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:id="@+id/ed_phone_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入手机号"
/>
<EditText
android:id="@+id/ed_pwd_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:id="@+id/but_login_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录"
/>
<Button
android:id="@+id/but_reg_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
/>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
2 。 注册
package yanjupeng20190404.myapplication.mvp.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 yanjupeng20190404.myapplication.R;
import yanjupeng20190404.myapplication.cont.Cont;
import yanjupeng20190404.myapplication.mvp.presenter.Presenter;
public class RegActivity extends AppCompatActivity implements Cont.RegViewInterface {
public EditText editText_regPhone , editText_regPwd;
public Button button_ok;
public Cont.PresenterInterface presenterInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reg);
presenterInterface = new Presenter<>(this);
editText_regPhone = findViewById(R.id.ed_reg_phone_id);
editText_regPwd = findViewById(R.id.ed_reg_pwd_id);
button_ok = findViewById(R.id.but_ok_id);
button_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phone = editText_regPhone.getText().toString();
String pwd = editText_regPwd.getText().toString();
presenterInterface.toReg(phone , pwd);
}
});
}
@Override
public void reFreshReg(String info) {
Toast.makeText(this , info , Toast.LENGTH_SHORT).show();
startActivity(new Intent(this , LoginActivity.class));
finish();
}
@Override
protected void onDestroy() {
super.onDestroy();
presenterInterface.fnish();
presenterInterface = null;
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".mvp.view.RegActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:id="@+id/ed_reg_phone_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入手机号"
/>
<EditText
android:id="@+id/ed_reg_pwd_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:id="@+id/but_ok_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="完成"
/>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
3 FragmentActivity
package yanjupeng20190404.myapplication.mvp.view;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.hjm.bottomtabbar.BottomTabBar;
import yanjupeng20190404.myapplication.R;
import yanjupeng20190404.myapplication.fragment.AFragment;
import yanjupeng20190404.myapplication.fragment.BFragment;
import yanjupeng20190404.myapplication.fragment.CFragment;
public class FragmentActivity extends AppCompatActivity {
public BottomTabBar bottomTabBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
bottomTabBar = findViewById(R.id.bottomTabBar_id);
bottomTabBar.init(getSupportFragmentManager())
.setChangeColor(Color.RED , Color.BLUE)
.setFontSize(40)
.setTabBarBackgroundColor(Color.YELLOW)
.addTabItem("首页" , R.mipmap.ic_launcher , AFragment.class)
.addTabItem("购物车" , R.mipmap.ic_launcher , BFragment.class)
.addTabItem("我的" , R.mipmap.ic_launcher , CFragment.class);
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".mvp.view.FragmentActivity">
<com.hjm.bottomtabbar.BottomTabBar
android:id="@+id/bottomTabBar_id"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.hjm.bottomtabbar.BottomTabBar>
</android.support.constraint.ConstraintLayout>
3-1 Afragment
package yanjupeng20190404.myapplication.fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import yanjupeng20190404.myapplication.R;
public class AFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(container.getContext()).inflate(R.layout.fragment_a_layout, null);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}
3-2 Bfragment
package yanjupeng20190404.myapplication.fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import yanjupeng20190404.myapplication.R;
import yanjupeng20190404.myapplication.adapter.MyAdapter1;
import yanjupeng20190404.myapplication.bean.Bean;
import yanjupeng20190404.myapplication.cont.Cont;
import yanjupeng20190404.myapplication.mvp.presenter.Presenter;
public class BFragment extends Fragment implements Cont.BfragmentInterface {
public RecyclerView recyclerView;
public Cont.PresenterInterface presenterInterface;
public MyAdapter1 adapter;
public CheckBox checkBox;
public TextView textView , pay;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(container.getContext()).inflate(R.layout.fragment_b_layout, null);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
recyclerView = view.findViewById(R.id.recyclerView_id);
checkBox