I followed this tutorial (http://www.vogella.com/tutorials/AndroidListView/article.html#expandablelistview)
for an expandable list view, in which I enter different shop names, categorized by the part of town they are located:

But there is obviously no need to have the same group several times (which is the case for Neukölln for example).
Here is what I tried to do:
SparseArray<Groups> groups = new SparseArray<Groups>();
DatabaseHandler db = new DatabaseHandler(this) ;
List<Shop> shops = db.getAllShops();
    Groups group = null ;
    String str = "null" ;
    int i = 0 ;
    for (Shop shop : shops){
        // if current shop's district differs from district of the shop of the last iteration
        if ( shop.getDistrict() != str ) {
            // making sure that empty group is not appended into groups in the first iteration
            if (group != null) {
                groups.append(i, group);
                i++;
            }
            // saving the district of the current shop
            str = shop.getDistrict();
            // creating a new group named after the current district
            group = new Groups(str);
        }
        // adding shop name to the current district
        group.subitems.add(shop.getName()) ;
    }
    // after last iteration the last group needs to be appended to the groups
    groups.append(i, group);
I hope you can understand the basic idea of my code. I sure it has to work out, because I went through it on paper and in theory it works. My first idea was that those if-statements are responsible, but I have no clue how to repair this.
 
     
     
    