コード例 #1
0
  /** Display all routes in an exapandable list */
  public void displayRoutes() {

    TramHunterDB db = new TramHunterDB();
    routes = db.getRoutes();
    db.close();

    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();

    for (int i = 0; i < routes.size(); i++) {
      Route route = routes.get(i);
      Map<String, String> curGroupMap = new HashMap<String, String>();
      curGroupMap.put("route", "Route " + route.getNumber());
      curGroupMap.put("to", route.getDestinationString());
      groupData.add(curGroupMap);

      List<Map<String, String>> children = new ArrayList<Map<String, String>>();
      List<Destination> destinations = route.getDestinations();

      for (Destination d : destinations) {
        Map<String, String> curChildMap = new HashMap<String, String>();
        curChildMap.put("destination", d.getDestination());
        children.add(curChildMap);
      }

      childData.add(children);
    }

    // Set up our adapter
    mAdapter =
        new SimpleExpandableListAdapter(
            this,
            groupData,
            R.layout.routes_list_row,
            new String[] {"route", "to"},
            new int[] {R.id.route_name, R.id.route_dest},
            childData,
            android.R.layout.simple_expandable_list_item_1,
            new String[] {"destination"},
            new int[] {android.R.id.text1, android.R.id.text2});

    setListAdapter(mAdapter);
  }