我正在開發一個餐廳應用程序。在這裏,我使用購物車頁面來查看用戶選擇結賬的食品項目。購物車商品使用RecyclerView列出,該商品有+ & - 按鈕增加&在結賬前減少產品數量。我的問題在這裏。TextView中的匿名錯誤
讓我們考慮的項目,如如下:
Result TextView
ChocoBar Rs25 - 4 + = 100 // Expected Result
Vennila Rs30 - 1 + = 30
同時點擊 「+」 按鈕,在ChocoBar
Result TextView
ChocoBar Rs25 - 5 + = 100 (set as 125 within fraction of second it is changed to 100)
Vennila Rs30 - 1 + = 30
但如果我使用gettext,
resultTextView is nothing but in code I used as holder.cartPriceDum
resultTextview.getText()。toString - >返回125作爲ChocoBar項目值。
GetText工作但setText不工作。 gettting messup。請幫助我,我花了更多時間來修復它。但我還沒有修復它。
mycode的情況如下:
holder.ivIncrease.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
clicked = true;
cartPrice = Integer.parseInt(holder.cartPrice.getText().toString());
InDeQuantity = Integer.parseInt(holder.cartCount.getText().toString());
if (null != mListener) {
cartRes.get(position).CartCount = (bigInt + 1);
notifyItemChanged(position);
mListener.onListFragmentInteraction(holder.cartRess);
}
UpdateCart(arg0);
}
private void UpdateCart(View view) {
String pID = cartRes.get(position).product_id;
int cartPrice = Integer.parseInt(holder.cartPrice.getText().toString());
int cartIndividualTotal = cartRes.get(position).subTotal;
int cartCount = cartRes.get(position).CartCount;
System.out.println("Restaurant" + " Check" + "Product ID " + pID + "Cart Price " + cartPrice +
" cartIndividual Total " + cartIndividualTotal + " CartCount " + cartCount);
CommonUtil.dbUtil.open();
CommonUtil.dbUtil.updateaddToCart(pID, cartPrice, cartCount, cartIndividualTotal);
Total = CommonUtil.dbUtil.getMultiply(pID);
CommonUtil.dbUtil.updateNetAmount(pID, Total);
setCartPrice(pID, holder);
view.invalidate();
/*--- Set all the updated value into the CartRes Class---*/
System.out.println("Cart Details" + cartRes.get(position).product_id + " " +
cartRes.get(position).CartproductName + " " + cartRes.get(position).CartcategoryName +
" " + cartCount + " " + cartPrice + " " + Total);
CartRes cartBasket = new CartRes(cartRes.get(position).product_id, cartRes.get(position).
CartproductName, cartRes.get(position).CartcategoryName,
cartCount, cartPrice, Total);
}
});
/*======================================= *** ==============================================*/
/*--- If Cart count is 1, then disable Decrement icon*/
if (InDeQuantity <= 1) {
holder.ivDecrease.setVisibility(View.INVISIBLE);
} else {
holder.ivDecrease.setVisibility(View.VISIBLE);
}
/*==================================== Decreasing Cart ====================================*/
holder.ivDecrease.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
clicked = true;
cartPrice = Integer.parseInt(holder.cartPrice.getText().toString());
InDeQuantity = Integer.parseInt(holder.cartCount.getText().toString());
if (null != mListener) {
if (InDeQuantity > 1) {
cartRes.get(position).CartCount = (bigInt - 1);
notifyItemChanged(position);
mListener.onListFragmentInteraction(holder.cartRess);
} else if (InDeQuantity <= 0) {
InDeQuantity = 1;
}
}
UpdateCart(arg0);
}
private void UpdateCart(View view) {
String pID = cartRes.get(position).product_id;
int cartPrice = Integer.parseInt(holder.cartPrice.getText().toString());
int cartCount = cartRes.get(position).CartCount;
int cartIndividualTotal = cartRes.get(position).subTotal;
CommonUtil.dbUtil.open();
CommonUtil.dbUtil.updateaddToCart(pID, cartPrice, cartCount, cartIndividualTotal);
System.out.println("Restaurant " + pID + " " + cartPrice + " " + cartCount + " " + cartIndividualTotal);
Total = CommonUtil.dbUtil.getMultiply(pID);
CommonUtil.dbUtil.updateNetAmount(pID, Total);
setCartPrice(pID, holder);
view.invalidate();
System.out.println("Cart Details" + cartRes.get(position).product_id + " " +
cartRes.get(position).CartproductName + " " + cartRes.get(position).CartcategoryName +
" " + cartCount + " " + cartPrice + " " + Total);
CartRes cartBasket = new CartRes(cartRes.get(position).product_id,
cartRes.get(position).CartproductName,
cartRes.get(position).CartcategoryName,
cartCount, cartPrice, Total);
}
});
private void setCartPrice(String pID, ViewHolder holder) {
Cursor cursor = CommonUtil.dbUtil.getCartIndividualPrice(pID);
if (cursor != null && cursor.moveToFirst()) {
int cartIndividualTotal = Integer.parseInt(cursor.getString(cursor.getColumnIndex(DbHelper.CART_TOTAL)));
holder.cartPriceDum.setText(String.valueOf(cartIndividualTotal));
Log.e("Restaurant", " ADapterCheck" + cartIndividualTotal + " " + holder.cartPriceDum.getText().toString());
}
}
對不起,即使移除view.invalidate()後結果也是一樣的。 –