购物车展示啊

package com.example.aason.zhushayuekaomini.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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.example.aason.zhushayuekaomini.R;
import com.example.aason.zhushayuekaomini.adapter.CartAdapter;
import com.example.aason.zhushayuekaomini.bean.CartBean;
import com.example.aason.zhushayuekaomini.contract.CartContract;
import com.example.aason.zhushayuekaomini.presenter.CartPresenter;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class Fragmenttwo extends Fragment implements CartContract.ICartView {
@BindView(R.id.rev)
XRecyclerView rev;
@BindView(R.id.ck)
CheckBox ck;
@BindView(R.id.btn)
Button btn;
Unbinder unbinder;
private CartPresenter cartPresenter;
private CartAdapter cartAdapter;
private List data;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragmenttwo, container, false);
    unbinder = ButterKnife.bind(this, view);
    rev.setLayoutManager(new LinearLayoutManager(getActivity()));
    cartPresenter = new CartPresenter(this);
    cartPresenter.goods(new HashMap());
    cartAdapter = new CartAdapter(getActivity());
    rev.setAdapter(cartAdapter);
    ck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked){
                for (CartBean.DataBean dataBean:data){
                    dataBean.isChecked=true;
                    for (CartBean.DataBean.ListBean listBean:dataBean.getList()){
                        listBean.isProdChecked=true;
                    }
                }
            }else{
                for (CartBean.DataBean dataBean:data){
                    dataBean.isChecked=false;
                    for (CartBean.DataBean.ListBean listBean:dataBean.getList()){
                        listBean.isProdChecked=false;
                    }
                }
            }
            cartAdapter.notifyDataSetChanged();
            getTouchPrice();
        }


    });
    return view;
}

@Override
public void onDestroyView() {
    super.onDestroyView();
    unbinder.unbind();
}

@Override
public void success(Object result) {
    CartBean cartBean = (CartBean) result;
    data = cartBean.getData();
    cartAdapter.setList(data);
}

@Override
public void fail(Object msg) {

}
private void getTouchPrice() {
    double touchprice = 0;
    for(CartBean.DataBean dataBean:data){
        for (CartBean.DataBean.ListBean listBean:dataBean.getList()){
            if (listBean.isProdChecked) {
                touchprice +=listBean.getPrice();
            }
        }
    }
    ck.setText("¥:"+touchprice);
}

}

你可能感兴趣的:(啊啊)