Can someone please tell me why the code below overwrites every element in the ArrayList with the most recent entry into the ArrayList? Or how to correctly add new elements of hashmaps to my ArrayList?
ArrayList<HashMap<String, String>> prodArrayList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> prodHashMap = new HashMap<String, String>();
public void addProd(View ap)
{
// test arraylist of hashmaps
prodHashMap.put("prod", tvProd.getText().toString());
prodArrayList.add(prodHashMap);
tvProd.setText("");
// check data ///
Log.e("myLog","Data prodArrayList in ADD Method Size = "+prodArrayList.size());
for(int i=0; i< prodArrayList.size();i++)
{
Log.e("myLog","Data prodArrayList in ADD Method = "+prodArrayList.get(i).toString());
}
}