【发布时间】:2016-05-25 06:11:13
【问题描述】:
我正在开发一个餐厅应用程序。在这里,我使用购物车页面来查看用户选择结帐的食品。购物车项目使用 RecyclerView 列出,该视图具有 + 和 - 按钮来增加和减少结帐前的产品数量。我的问题就在这里。
让我们考虑如下项目:
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 无效。搞砸了。请帮帮我,我花了更多时间修复它。但我还没有修复它。
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());
}
}
【问题讨论】:
标签: android textview android-recyclerview