简体   繁体   English

如果数量增加或减少,总体效果如何?

[英]how will effect in total, if qty will increase or decrease?

I want if i increase the qty then total should also effect and when decrease the quantity,from the total also should subtract.on increase and decrease qty amount working perfect but there is a issue in total,How can i do this,Please help if someone have idea?我想如果我增加数量,那么总数也应该起作用,当减少数量时,总数也应该减去。关于增加和减少数量的工作完美但总共有一个问题,我该怎么做,请帮忙如果有人知道吗?

     holder.inc.setOnClickListener( new View.OnClickListener(){// this method is for increase the quantity by the cart_id
                        @Override
                        public void onClick(View view) {

                            float amount=0,Amt_with_cgst_sgst=0,qty_return=0;;
                            float gst= Float.parseFloat( holder.txt_gst.getText().toString() );
                            bill_id= Integer.parseInt( holder.txt_bill_id.getText().toString() );
                            Cat_id= Integer.parseInt( holder.txt_cart_id.getText().toString() );
                            float qty= Float.parseFloat( holder.txt_per_qty.getText().toString());
                            float price = Float.parseFloat( holder.txt_price.getText().toString() );
                            float inc_qty= Float.parseFloat( holder.inc_quantity.getText().toString());
                            float CGST=  Float.parseFloat(holder.txt_cgst.getText().toString());
                            float SGST= Float.parseFloat( holder.txt_sgst.getText().toString());
                           if(inc_qty<billlist.get(i).getC_qunanity()){ //it will increase the value  till that value  exit before the change only
                                inc_qty++;
                                holder.inc_quantity.setText(String.valueOf(inc_qty));
                             }
                            float sales_qty= billlist.get( i).getC_qunanity();
                            qty_return = sales_qty+inc_qty;
                            amount =(price/qty)*inc_qty;
                            float sales_amt= billlist.get(i).getC_Amount();
                            float amt_return = sales_amt+amount;
                            Float cgst_sgst =amount*(CGST+SGST)/100;
                            Amt_with_cgst_sgst= amount+cgst_sgst;
                            holder.txt_amount.setText(String.valueOf(Amt_with_cgst_sgst));

                            Add_Sales.txt_grand_total.setText( String.valueOf(getTotal_Add( Amt_with_cgst_sgst )));//getTotal is a method for calculating the total

                            holder.desc.setOnClickListener( new View.OnClickListener() {//this method is for decrease the quantity by the cart_id
                            @Override
                            public void onClick(View view){
                                float gst= Float.parseFloat( holder.txt_gst.getText().toString() );

                            bill_id = Integer.parseInt( holder.txt_bill_id.getText().toString() );
                            Cat_id = Integer.parseInt( holder.txt_cart_id.getText().toString() );

                            float qty = Float.parseFloat( holder.txt_per_qty.getText().toString());
                            float price = Float.parseFloat( holder.txt_price.getText().toString() );
                          //  float Amt= Float.parseFloat( holder.txt_amount.getText().toString());
                            float inc_qty= Float.parseFloat( holder.inc_quantity.getText().toString());
                            float CGST =  Float.parseFloat(holder.txt_cgst.getText().toString());
                            float SGST = Float.parseFloat( holder.txt_sgst.getText().toString());
                            float qty_return=0;
                            if(inc_qty>0){
                                inc_qty--;
                                holder.inc_quantity.setText(String.valueOf(inc_qty));
                                float sales_qty= billlist.get(i).getC_qunanity();
                                qty_return  = sales_qty-inc_qty;
                              }
                            float amount =(price/qty)*inc_qty;//calculating the amount by price or qty without gst
                            float sales_amt = billlist.get(i).getC_Amount();
                            float amt_return = sales_amt-amount;
                            Float cgst_sgst = amount*(CGST+SGST)/100;

//calculating amount with gst float Amt_with_cgst_sgst= amount+cgst_sgst; //用gst计算金额 float Amt_with_cgst_sgst= amount+cgst_sgst; holder.txt_amount.setText(String.valueOf(Amt_with_cgst_sgst));//setting the amount after doing calculation holder.txt_amount.setText(String.valueOf(Amt_with_cgst_sgst));//计算后设置金额

                           Add_Sales.txt_grand_total.setText( String.valueOf(getTotal_Sub(Amt_with_cgst_sgst )));

    public float getTotal_Add(float price){ //calculating the total amount here
            for(int i=0;i<billlist.size();i++){
                price+=billlist.get( i ).getC_Amount();//getting the amount by the position wise
            }
            return price;
        }

Yes you can use mutable live data for the quantity and billing amount you have to take 2 mutable live data variable, and observe quntity live data when you change value it reflect in obesrver and than do process on update value and again push the value in price data是的,您可以将可变实时数据用于数量和计费金额,您必须采用 2 个可变实时数据变量,并在您更改反映在 obesrver 中的值时观察 quntity 实时数据,而不是处理更新值并再次推动价格值数据

var qua=Mutablelivedata() var price=MutableLivedate() var qua=Mutablelivedata() var price=MutableLivedate()

qua.observe(ths(@lifecyle may be activity or fragment),Observe{ //here you can get updated qua value qua.observe(ths(@lifecyle可能是activity或者fragment),Observe{ //这里可以获取更新的qua值

 price.value=value after opration

}) })

use data two data binding so reflect使用数据两个数据绑定所以反映

when ever user click - or + icons call this method当用户单击-+图标时调用此方法

private void updateProductPrice(int quantity){
    itemPrice=(quantity*itemCostPrice);
    tv_Price.setText("$"+itemPrice);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM