0

i tried so many things to do this, but still cant add more arraylist

please help me.

this is my code :

 public static ArrayList<HashMap<String, String>> cartList;

    cart.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            // Get the position from the results
            HashMap<String, String> resultp = new HashMap<String, String>();
            resultp = data.get(position);
            cartList = new ArrayList<HashMap<String, String>>();

            HashMap<String, String> map = new HashMap<String, String>();
            map.put("nama", resultp.get(SellerActivity.TITLE));
            map.put("harga", resultp.get(SellerActivity.HARGA));
            map.put("link_gambar", resultp.get(SellerActivity.WEBSITE));
            map.put("website", resultp.get(SellerActivity.GAMBAR));
            cartList.add(map);

        }
    });

i want the output is list of my arraylist, but on this situation i just can add one array. thanks..

UPDATE :

now i want to add checkbox and button to delete item from arraylist, have a clue with that?

4
  • java.dzone.com/articles/hashmap-%E2%80%93-single-key-and Commented Jun 18, 2014 at 5:17
  • 1
    @zacky it's unclear what you are asking Commented Jun 18, 2014 at 5:18
  • Question is unclear indeed. Commented Jun 18, 2014 at 5:26
  • thanks to anil, he's know what i mean :) Commented Jun 18, 2014 at 5:56

1 Answer 1

1

You create cartList each time when user click on cart. Maybe, the problem can be solved if you delete string cartList = new ArrayList<HashMap<String, String>>(); from the OnClick and rewrite the first string of your sample code: public static ArrayList<HashMap<String, String>> cartList = new ArrayList<HashMap<String, String>>()?

Sign up to request clarification or add additional context in comments.

1 Comment

Not at all. But i recommend you ask more complete questions :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.