Android 如果数量增加或减少,总体效果如何?
我想如果我增加了数量,那么总数也应该生效,当减少数量时,总数也应该减去。增加和减少数量的数量工作得很好,但是总数有一个问题,我怎么做,如果有人有想法,请帮助Android 如果数量增加或减少,总体效果如何?,android,android-recyclerview,Android,Android Recyclerview,我想如果我增加了数量,那么总数也应该生效,当减少数量时,总数也应该减去。增加和减少数量的数量工作得很好,但是总数有一个问题,我怎么做,如果有人有想法,请帮助 holder.inc.setOnClickListener( new View.OnClickListener(){// this method is for increase the quantity by the cart_id @Override
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;
holder.inc.setOnClickListener(new View.OnClickListener(){//此方法用于通过购物车id增加数量
@凌驾
公共void onClick(视图){
浮动金额=0,带现金的金额=0,数量返回=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_quantity=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());
如果(包括数量0){
公司数量--;
holder.inc_quantity.setText(String.valueOf(inc_quantity));
浮动销售数量=billlist.get(i).getC_qunanity();
退货数量=销售数量-包含数量;
}
浮动金额=(价格/数量)*包含数量;//按价格或数量计算金额,不含gst
浮动销售金额=billlist.get(i).getC金额();
浮动金额=退货金额=销售金额-金额;
浮动现金等价物=金额*(现金等价物+现金等价物)/100;
//使用gst浮动金额计算金额,使用金额=金额+金额;
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;
}
Add_Sales.txt_grand_total.setText(String.valueOf(getTotal_Sub(Amt_with_cgst_sgst));
公共浮动getTotal_Add(浮动价格){//计算此处的总金额
对于(int i=0;i是),您可以对数量和账单金额使用可变实时数据。您必须使用2个可变实时数据变量,并在更改值时观察质量实时数据,该值反映在OBESVER中,然后处理更新值,并再次推送价格数据中的值
var qua=Mutablelivedata()
var price=MutableLivedate()
质量观察(ths(@生命周期可能是活动或碎片),观察{
//在这里您可以获得更新的qua值
price.value=value after opration
})
使用数据两个数据绑定,以便在用户单击-
或+
图标调用此方法时反映
private void updateProductPrice(int quantity){
itemPrice=(quantity*itemCostPrice);
tv_Price.setText("$"+itemPrice);
}
只需单击“增加”和“减少”按钮,即可进行计算和更新数据。只需选中“执行”即可it@Piyush这发生在数据库中,但不希望通过更新数据库来更改数据库而不影响iti。我不知道如何更改,请帮助我是否要向数据库添加新列?如果不想,则不需要更改表。.也分享你的code@rachna你是指购物车的总价,还是?对我来说,我将购物车数据存储到本地数据库(sqlite)中
当我更新商品数量时,我也会更新购物车表,然后总数将被更新,但我不想这样做,实际上这不是购物车的情况,在购物车的情况下,我也会这样做,但当商品从客户端返回时,客户将返回,然后数量将从当时的退出数量减少,用户将单击添加返回然后,购物车正在更新