2017-06-09 132 views
-7
public class CartController extends Application { 
    final String TAG = CartController.class.getSimpleName(); 
    public static ArrayList<ProductsDetail> productCartArrayList = 
        new ArrayList<ProductsDetail>(); 
    private CartModel cartModelInstance = new CartModel(); 


    public ProductsDetail getProductsInCartController(int pPosition) { 
    // Log.v(TAG,"******"+productCartArrayList.get(pPosition)); 
     return productCartArrayList.get(pPosition); 
    } 

    public void setProductsInCartController(ProductsDetail products) { 
     productCartArrayList.add(products); 
    } 

    public void removeProductsFromCartController(ProductsDetail products) { 
     productCartArrayList.remove(products); 
    } 

    public CartModel getCart() { 
     return cartModelInstance; 
    } 

    public int getProductsArraylistSize() { 
     return productCartArrayList.size(); 
    } 

    public ArrayList<ProductsDetail> getProductArray() { 
     return productCartArrayList; 
    } 
} 
+0

你做了什麼或嘗試過!!?!! – shadygoneinsane

+0

您是否使用過任何IDE來調試您的代碼? – reporter

回答

-1
public ProductsDetail getProductsInCartController(int pPosition) { 
    // Log.v(TAG,"******"+productCartArrayList.get(pPosition)); 
     return productCartArrayList.get(pPosition); 
    } 

有此功能的隱患,如果p位置比productCartArrayList.size()越大,將拋出IndexOutOfBoundsException異常。

相關問題