@Override
 public void onCheckedChanged(RadioGroup group, int checkedId) {
   View v = group.findViewById(checkedId);
   if (!(v instanceof RadioButton)) {
     return;
   }
   RadioButton b = (RadioButton) v;
   String message = (String) b.getTag();
   app.settings().setDefaultMessage(message);
 }
  public void updateUI() {
    radioGroup.removeAllViews();
    radioGroup.setOnCheckedChangeListener(null);

    String[] messageOptions = app.settings().getMessageOptionsArray();
    RadioButton buttonToCheck = new RadioButton(getContext());
    for (int i = 0; i < messageOptions.length; i++) {
      RadioButton button = new RadioButton(getContext());
      button.setText(messageOptions[i]);
      button.setTag(messageOptions[i]);
      button.setId(i);
      if (app.settings().getDefaultMessage().equals(messageOptions[i])) {
        buttonToCheck = button;
      }
      radioGroup.addView(button);
    }
    buttonToCheck.setChecked(true);
    radioGroup.setOnCheckedChangeListener(this);

    removeOptionButton.setEnabled(messageOptions.length != 1);
  }
  private void startRemoveOptionDialog() {
    final String[] options = app.settings().getMessageOptionsArray();

    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(R.string.pref_remove_apology_dialog_title);
    builder.setItems(
        options,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            app.settings().removeMessageOption(options[which]);
            updateUI();
          }
        });
    builder.show();
  }