Android购物车 + Mvp + 二级联动以及数量价格加减 + 全选反选 + 登录注册 + 回显 + 水波图 +详情展示

这篇博客详细介绍了如何在Android应用中实现购物车功能,包括使用MVP架构,二级联动,数量价格加减,全选反选功能。同时,文章涵盖了登录注册流程,FragmentActivity的使用,以及A、B、C三个Fragment的交互。还涉及到商品详情展示,水波图效果的实现,并提到了Bean类、工具类的组织以及购物车和详情展示的适配器编写。文章最后提及了所需的依赖库。
摘要由CSDN通过智能技术生成

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 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值