public Dialog createSelectGroupDialog(final MainActivity activity, final BusHandler busHandler) {
    Log.i(TAG, "createParticipantsDialog()");
    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.selectgroupdialog);

    ArrayAdapter<String> groupListAdapter =
        new ArrayAdapter<String>(activity, android.R.layout.test_list_item);
    final ListView groupList = (ListView) dialog.findViewById(R.id.groupList);
    groupList.setAdapter(groupListAdapter);

    List<String> groups = new ArrayList<String>(busHandler.listHostedGroups());
    List<String> joinedGroups = busHandler.listJoinedGroups();

    // Combine the list of Hosted Groups and Joined Groups
    for (String group : joinedGroups) {
      if (!groups.contains(group)) {
        groups.add(group);
      }
    }

    // Transfer groups from the ArrayList given by the GroupManager to the local ArrayAdapter
    for (String group : groups) {
      groupListAdapter.add(group);
    }
    groupListAdapter.notifyDataSetChanged();

    groupList.setOnItemClickListener(
        new ListView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Create the get peers dialog after the user selects the group
            String name = groupList.getItemAtPosition(position).toString();
            Bundle args = new Bundle();
            args.putString("groupName", name);
            activity.showDialog(MainActivity.DIALOG_GET_PEERS_ID, args);
            /*
             * Android likes to reuse dialogs for performance reasons.  If
             * we reuse this one, the list of channels will eventually be
             * wrong since it can change.  We have to tell the Android
             * application framework to forget about this dialog completely.
             */
            activity.removeDialog(MainActivity.DIALOG_SELECT_GET_PEER_GROUP_ID);
          }
        });

    Button ok = (Button) dialog.findViewById(R.id.cancelSelectGroupButton);
    ok.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            activity.removeDialog(MainActivity.DIALOG_SELECT_GET_PEER_GROUP_ID);
          }
        });

    return dialog;
  }
  public Dialog createJoinGroupDialog(
      final MainActivity activity, final BusHandler busHandler, final UIHandler uiHandler) {
    Log.i(TAG, "createJoinGroupDialog()");
    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.joingroupdialog);

    ArrayAdapter<String> groupListAdapter =
        new ArrayAdapter<String>(activity, android.R.layout.test_list_item);
    final ListView groupList = (ListView) dialog.findViewById(R.id.joinGroupList);
    groupList.setAdapter(groupListAdapter);

    List<String> groups = busHandler.listGroups();

    // remove all already hosted and joined groups
    groups.removeAll(busHandler.listHostedGroups());
    groups.removeAll(busHandler.listJoinedGroups());

    // Transfer groups from the ArrayList given by the GroupManager to the local ArrayAdapter
    for (String group : groups) {
      groupListAdapter.add(group);
    }
    groupListAdapter.notifyDataSetChanged();

    groupList.setOnItemClickListener(
        new ListView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Call join group on the selected advertised group
            String name = groupList.getItemAtPosition(position).toString();
            activity.joinGroup(name);
            /*
             * Android likes to reuse dialogs for performance reasons.  If
             * we reuse this one, the list of channels will eventually be
             * wrong since it can change.  We have to tell the Android
             * application framework to forget about this dialog completely.
             */
            activity.removeDialog(MainActivity.DIALOG_JOIN_GROUP_ID);
          }
        });

    Button ok = (Button) dialog.findViewById(R.id.cancelJoinGroupButton);
    ok.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            activity.removeDialog(MainActivity.DIALOG_JOIN_GROUP_ID);
          }
        });

    return dialog;
  }