0

ここに私の製品の ListView があります。ユーザーが ListView の追加ボタンをクリックするたびに、アクティビティにあるが ListView にはない totalBill TextView を更新したいと考えています。私の問題は、CustomAdapter では、ボタンのクリック時にアクティビティ クラスにある TextView を更新できないことです。これを達成する方法は?

        tvId = (TextView) v.findViewById(R.id.itemId);
        tvName = (TextView) v.findViewById(R.id.itemName);
        tvPrice = (TextView) v.findViewById(R.id.itemPrice);
        tvQty = (TextView) v.findViewById(R.id.quantity);
        plusButton = (ImageButton) v.findViewById(R.id.addButton);
        minusButton = (ImageButton) v.findViewById(R.id.minusButton);
    }
    plusButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int qty = Integer.parseInt(tvQty.getText().toString());
            double itemPrice=Double.parseDouble(tvPrice.getText().toString());
            tvQty.setText(String.valueOf(++qty));
            ShoppingCart2 cart=new ShoppingCart2();
            cart.addQuantity(qty, itemPrice);
        }
    });

上記のコードは CustomAdapter にあり、以下はアクティビティ クラスにあります。

    public void addQuantity(int quantity, Double itemPrice) {
    try {
        Double totalPrice = quantity * itemPrice;
        totalBill = totalBill.add(BigDecimal.valueOf(totalPrice));
        totalBill = totalBill.setScale(0, BigDecimal.ROUND_HALF_UP);
        tvTotalBill = (TextView) findViewById(R.id.tvTotalBill);
        tvTotalBill.setText(totalBill.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

addQuantity 関数で NullPointer 例外が発生しています。これを行う他の方法はありますか?

4

0 に答える 0