Issue
I am writing a Shopping Cart App in which i am allowing user to choose items to buy and add their required items to Cart, for this i have given two different tabs,
First Tab, to browse products
Second Tab, to browse Items in Cart [User Added]
Here I am facing a small problem. I am not getting updated quantity in Cart, but getting changes in total price, whenever i do change in Item Quantity.
So, tell me what I need to add in my code to get changes in Quantity also, How to Update Quantity while moving between Tabs
I have written below code in onResume() under ViewCartActivity.java:
@Override
protected void onResume()
{
super.onResume();
if (Constants.mItem_Detail.size() == 0)
{
return;
}
Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get(0).get(SingleTrackActivity.KEY_TOTAL));
for (int i = 1; i < Constants.mItem_Detail.size(); i++)
{
mGTotal = mGTotal + Double.parseDouble(Constants.mItem_Detail.get(i).get(SingleTrackActivity.KEY_TOTAL));
}
mGrandTotal = String.valueOf(mGTotal);
mTxtViewGrandTotal.setText(mGrandTotal);
myTextVeiwGrandTotal.setText(mGrandTotal);
mTxtViewGrandTotal.setText(new DecimalFormat("##.##").format(mGTotal));
mTotal = String.valueOf(Constants.mItem_Detail.size());
mItems.setText(mTotal);
}
Please see below screen shot, i have updated quantity of an item from 1 to 10, therefore i got changes in Total Amount, but did not get any change in Quantity getting 1 only,whenever i am moving between tabs i am facing this problem:
Using Below code in Products.java class to update quantity of an Item:
for (int i = 0; i < Constants.mItem_Detail.size(); i++) {
if (Constants.mItem_Detail.get(i).get(TAG_NAME)
.equals(song_name)) {
Constants.mItem_Detail.remove(i);
break;}
Note:
If i will not move to Cart Tab from Products Tab, I am able to view changes in Quantity of an Item, but once i will move to Cart Tab from Products Tab then i am not getting changes in Quantity of an Item...
Solution
I guess you are on right path, just check with patience, add items to cart then update cart items, wait for few seconds, i hope it will update your cart itself.....
Your code looks like good to me:
for (int i = 0; i < Constants.mItem_Detail.size(); i++) {
if (Constants.mItem_Detail.get(i).get(TAG_NAME)
.equals(song_name)) {
Constants.mItem_Detail.remove(i);
break;
Answered By - ASMUIRTI
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.