Well, I think there are various approaches, but one approach would be:
a) Continue to store groceryname -> quantity mappings in the shared preferences object, just like before.
b) Change the ArrayList<String> to store strings that look like "5 bananas", so that that will be what shows up in the ListView.
c) Every time you go to add something new to the ArrayList, you need to add something more like (quantity + " " + groceryName).
d) Every time they click on something, and you need to figure out what they clicked on, then you need to split the String up into the quantity & name parts (by looking for the first space). Once you do that, you can use the name part to index into the sharedPreference mapping.