Custom ListView for Android

During development of YartzaitZmanim application for Android, I found a wonderful tutorial how to create custom ListView.
Custom ListView | Android Developer Tutorial (Part 17)

But the problem was that after each initialization of ListView, list items were multiplied.
The solution is to emty list ArrayList before each populateList function call.

    private void populateList() {
list.clear();
    HashMap temp = new HashMap();
    temp.put("pen","MONT Blanc");
    temp.put("price", "200.00$");
    temp.put("color", "Silver, Grey, Black");
    list.add(temp);
    HashMap temp1 = new HashMap();
    temp1.put("pen","Gucci");
    temp1.put("price", "300.00$");
    temp1.put("color", "Gold, Red");
    list.add(temp1);
    HashMap temp2 = new HashMap();
    temp2.put("pen","Parker");
    temp2.put("price", "400.00$");
    temp2.put("color", "Gold, Blue");
    list.add(temp2);
    HashMap temp3 = new HashMap();
    temp3.put("pen","Sailor");
    temp3.put("price", "500.00$");
    temp3.put("color", "Silver");
    list.add(temp3);
    HashMap temp4 = new HashMap();
    temp4.put("pen","Porsche Design");
    temp4.put("price", "600.00$");
    temp4.put("color", "Silver, Grey, Red");
    list.add(temp4);
    }

2 comments

  1. I tried, but it seems for me little bit more complicated as native code 😉
    Lack of time is the biggest problem here. I just want to release proof-of-concept version and then we’ll see where to go further.

Leave a Reply

%d bloggers like this: