Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a simple shopping cart project. Currently, trying to add custom items via onClick from one RecyclerView and have it added to a new seperate ArrayList that will show in the cart RecyclerView.

I'm able to add new blank custom objects to the ArrayList but can't seem to figure out how to add the selected item. I tried passing position through a couple of parts none working. Here is the code:
<pre>
   mAdapter.setOnItemClickListener(new MainAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                addToCart(position);
            }
        });
    }

    public void addToCart(int position){
        cartList.add(new Inventory());

    }


What I have tried:

I've tried inserting position into the add().
Posted
Updated 5-Nov-20 18:54pm

1 solution

As a noob I thought I could just straight up add() the element in position. However, I used the position to access the object and use the appropriate getters to include in the adding process.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900