全选加价格求和

public class Fragment_One extends Fragment {
private CheckBox checkBox1;
private RecyclerView rec_view;
private Presenter presenter;
private TextView sum;
private ShopAdapter shopAdapter;
private List<ShowBean.DataEntity> list;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
checkBox1 = view.findViewById(R.id.checkbox1);
rec_view = view.findViewById(R.id.rec_view);
LinearLayoutManager linearLayoutManager =new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
rec_view.setLayoutManager(linearLayoutManager);
sum = view.findViewById(R.id.sum);
presenter = new Presenter(this);
presenter.getPress();

    checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checkAllOrNot(isChecked);
        }


    });
    return view;
}

public void getViewShow(final String data) {
    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Gson gson =new Gson();
            ShowBean showBean = gson.fromJson(data, ShowBean.class);
            list = showBean.getData();
            list.remove(0);
            shopAdapter = new ShopAdapter(getActivity(), list);
            rec_view.setAdapter(shopAdapter);
        }
    });
}

private void checkAllOrNot(boolean isChecked) {
    int prices = 0;
    for (int i = 0; i <list.size() ; i++) {
        ShowBean.DataEntity dataEntity = list.get(i);
        dataEntity.setCheck(isChecked);
        for (int j = 0; j < list.get(i).getList().size(); j++) {
            list.get(i).getList().get(j).setCheck(isChecked);
           if (checkBox1.isChecked()){
               int num = list.get(i).getList().get(j).getNum();
               double price = list.get(i).getList().get(j).getPrice();
               prices+=num*price;
           }
        }
        sum.setText("总价为:"+prices);
    }
        shopAdapter.notifyDataSetChanged();
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值