Java Code Examples for android.support.v7.app.AlertDialog#getButton()

The following examples show how to use android.support.v7.app.AlertDialog#getButton() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormDialog.java    From padland with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    final AlertDialog d = (AlertDialog)getDialog();
    if(d != null)
    {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if( validateForm() ) {
                    saveData();
                    callbackObject.onDialogSuccess();
                    callbackObject.onDialogDismiss();
                    d.dismiss();
                }
            }
        });
    }
}
 
Example 2
Source File: PriceRangePickerDialogFragment.java    From MaterialRangeSlider with Apache License 2.0 6 votes vote down vote up
@Override
    public void onStart() {
        super.onStart();

//         Override onClickListener so dialog is not closed when user clicks reset
        AlertDialog d = (AlertDialog) getDialog();
        if (d != null) {
            Button negativeButton = d.getButton(Dialog.BUTTON_NEUTRAL);
            negativeButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    priceSlider.reset();
                    priceSlider.invalidate();
                }
            });
        }
    }
 
Example 3
Source File: CreateScriptDialog.java    From BusyBox with Apache License 2.0 6 votes vote down vote up
@Override public void onStart() {
  super.onStart();

  AlertDialog dialog = (AlertDialog) getDialog();
  Radiant radiant = Radiant.getInstance(getActivity());
  dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(radiant.primaryTextColor());

  positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
  positiveButton.setTextColor(radiant.accentColor());
  positiveButton.setEnabled(false);

  editFileName.setOnFocusChangeListener(new View.OnFocusChangeListener() {

    @Override public void onFocusChange(View v, boolean hasFocus) {
      fromUser = hasFocus;
    }
  });

  editScriptName.addTextChangedListener(scriptNameTextWatcher);
  editFileName.addTextChangedListener(fileNameTextWatcher);

  KeyboardUtils.showKeyboard(editScriptName, true);
}
 
Example 4
Source File: UpdateMetadataDialog.java    From privacy-friendly-passwordgenerator with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    AlertDialog dialog = (AlertDialog) getDialog();
    if (dialog != null) {
        Button positiveButton = dialog.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateMetadata(oldMetaData.getITERATION());
                if (closeDialog) {
                    dismiss();
                }

            }
        });
    }
}
 
Example 5
Source File: FragmentSimpleDebtEdit.java    From fingen with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new OnOkListener());
    }
    Dialog dialog = getDialog();
    if (dialog != null)
    {
        int width = ViewGroup.LayoutParams.MATCH_PARENT;
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialog.getWindow().setLayout(width, height);
    }
}
 
Example 6
Source File: HeaderDialog.java    From HeaderDialog with MIT License 6 votes vote down vote up
@Override
public AlertDialog show() {
    AlertDialog alertDialog = super.show();

    Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
            "medium.ttf");

    Button bPos = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
    Button bNeg = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
    Button bNeu = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);

    if (bPos!=null)
        bPos.setTypeface(tf);

    if (bNeg!=null)
        bNeg.setTypeface(tf);

    if (bNeu!=null)
        bNeu.setTypeface(tf);

    return alertDialog;
}
 
Example 7
Source File: FragmentAmountEdit.java    From fingen with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    mAmountEditor.requestFocus();
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mAmountEditor.getCabbage().getID() < 0) {
                    //show error
                    mAmountEditor.showCabbageError();
                } else {
                    mOnComplete.onComplete(mAmountEditor.getAmount().multiply(new BigDecimal((mAmountEditor.getType() > 0) ? 1 : -1)), mAmountEditor.getCabbage());
                    dismiss();
                }
            }
        });
    }
}
 
Example 8
Source File: FragmentProductEntryEdit.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new OnOkListener());
    }
    Dialog dialog = getDialog();
    if (dialog != null) {
        int width = ViewGroup.LayoutParams.MATCH_PARENT;
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialog.getWindow().setLayout(width, height);
    }
}
 
Example 9
Source File: ColorPickerDialogPreference.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    AlertDialog dialog = (AlertDialog) getDialog();

    // http://stackoverflow.com/a/16972670/1048340
    //noinspection ConstantConditions
    dialog.getWindow()
            .clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

    // Do not dismiss the dialog when clicking the neutral button.
    Button neutralButton = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
    if (neutralButton != null) {
        neutralButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rootView.removeAllViews();
                switch (dialogType) {
                    case TYPE_CUSTOM:
                        dialogType = TYPE_PRESETS;
                        ((Button) v).setText(
                                customButtonStringRes != 0 ? customButtonStringRes : R.string.cpv_custom);
                        rootView.addView(createPresetsView());
                        break;
                    case TYPE_PRESETS:
                        dialogType = TYPE_CUSTOM;
                        ((Button) v).setText(
                                presetsButtonStringRes != 0 ? presetsButtonStringRes : R.string.cpv_presets);
                        rootView.addView(createPickerView());
                }
            }
        });
    }
}
 
Example 10
Source File: ColorPickerDialog.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    AlertDialog dialog = (AlertDialog) getDialog();

    // http://stackoverflow.com/a/16972670/1048340
    //noinspection ConstantConditions
    dialog.getWindow()
            .clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

    // Do not dismiss the dialog when clicking the neutral button.
    Button neutralButton = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
    if (neutralButton != null) {
        neutralButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rootView.removeAllViews();
                switch (dialogType) {
                    case TYPE_CUSTOM:
                        dialogType = TYPE_PRESETS;
                        ((Button) v).setText(
                                customButtonStringRes != 0 ? customButtonStringRes : R.string.cpv_custom);
                        rootView.addView(createPresetsView());
                        break;
                    case TYPE_PRESETS:
                        dialogType = TYPE_CUSTOM;
                        ((Button) v).setText(
                                presetsButtonStringRes != 0 ? presetsButtonStringRes : R.string.cpv_presets);
                        rootView.addView(createPickerView());
                }
            }
        });
    }
}
 
Example 11
Source File: FragmentCabbageEdit.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new OnOkListener());
    }
}
 
Example 12
Source File: FragmentSmsMarkerEdit.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new OnOkListener());
    }
}
 
Example 13
Source File: FragmentSenderEdit.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new OnOkListener());
    }
    Dialog dialog = getDialog();
    if (dialog != null) {
        int width = ViewGroup.LayoutParams.MATCH_PARENT;
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialog.getWindow().setLayout(width, height);
    }
}
 
Example 14
Source File: SslErrorDialogFragment.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
private void showExtendedMessage(@NonNull AlertDialog alertDialog) {
    TextView textView = (TextView) alertDialog.findViewById(android.R.id.message);
    Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
    if (textView != null) {
        textView.setText(R.string.ssl_error_display_message_extended);
        neutralButton.setEnabled(false);
    }
}
 
Example 15
Source File: MainActivity.java    From journaldev with MIT License 5 votes vote down vote up
public void withItems(View view) {

        final String[] items = {"Apple", "Banana", "Orange", "Grapes"};
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("List of Items")

                .setItems(items, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(), items[which] + " is clicked", Toast.LENGTH_SHORT).show();
                    }
                });

        builder.setPositiveButton("OK", null);
        builder.setNegativeButton("CANCEL", null);
        builder.setNeutralButton("NEUTRAL", null);
        builder.setPositiveButtonIcon(getResources().getDrawable(android.R.drawable.ic_menu_call, getTheme()));
        builder.setIcon(getResources().getDrawable(R.drawable.jd, getTheme()));

        AlertDialog alertDialog = builder.create();

        alertDialog.show();

        Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        button.setBackgroundColor(Color.BLACK);
        button.setPadding(0, 0, 20, 0);
        button.setTextColor(Color.WHITE);
    }
 
Example 16
Source File: ListActivity.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public void setDialog(AlertDialog dialog) {
    mDialog = dialog;
    mPositive = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    mNegative = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
    mNeutral = dialog.getButton(DialogInterface.BUTTON_NEUTRAL);
    mPositive.setOnClickListener(this);
    mNegative.setOnClickListener(this);
    mNeutral.setOnClickListener(this);
}
 
Example 17
Source File: SettingsActivity.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public void setDialog(AlertDialog dialog) {
    mDialog = dialog;
    mPositive = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    mNegative = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
    mNeutral = dialog.getButton(DialogInterface.BUTTON_NEUTRAL);
    mPositive.setOnClickListener(this);
    mNegative.setOnClickListener(this);
    mNeutral.setOnClickListener(this);
}
 
Example 18
Source File: CreatePublicChannelDialog.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private void updateButtons(AlertDialog dialog) {
    final Button positive = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    final Button negative = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
    positive.setText(nameEntered ? R.string.create : R.string.next);
    negative.setText(nameEntered ? R.string.back : R.string.cancel);
}
 
Example 19
Source File: FListCharSelectionPopup.java    From AndFChat with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();    //Call show on default first so we can override the handlers

    final AlertDialog dialog = (AlertDialog) getDialog();
    if (dialog == null) {
        return;
    }

    final Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String characterName = ((ArrayAdapter<String>)charSelector.getAdapter()).getItem(charSelector.getSelectedItemPosition());

            sessionData.clear();

            // Reset data only when new character connects
            if (sessionData.getCharacterName() == null || !sessionData.getCharacterName().equals(characterName)) {
                chatroomManager.clear();
                characterManager.clear();

                sessionData.setCharacterName(characterName);
            }
            // Websocket is connected?
            if (connection.isConnected()) {

                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        button.setEnabled(false);
                        button.setText(R.string.connecting);
                    }
                };

                Ln.i("Connected to WebSocket!");
                Ln.d("loading logs");
                historyManager.loadHistory();
                // Identify the character
                connection.identify();
            }
        }
    });

    // Cant close dialog
    dialog.setCanceledOnTouchOutside(false);
}
 
Example 20
Source File: FragmentDateFilterEdit.java    From fingen with Apache License 2.0 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int range;
                int modifier;
                switch (mRadioGroupRange.getCheckedRadioButtonId()) {
                    case R.id.radioButtonDateRangeDay:
                        range = DATE_RANGE_DAY;
                        break;
                    case R.id.radioButtonDateRangeWeek:
                        range = DATE_RANGE_WEEK;
                        break;
                    case R.id.radioButtonDateRangeMonth:
                        range = DATE_RANGE_MONTH;
                        break;
                    case R.id.radioButtonDateRangeYear:
                        range = DATE_RANGE_YEAR;
                        break;
                    default:
                        range = DATE_RANGE_MONTH;
                }
                switch (mRadioGroupModifier.getCheckedRadioButtonId()) {
                    case R.id.radioButtonDateRangeCurrent:
                        modifier = DATE_RANGE_MODIFIER_CURRENT;
                        break;
                    case R.id.radioButtonDateRangeLast:
                        modifier = DATE_RANGE_MODIFIER_LAST;
                        break;
                    case R.id.radioButtonDateRangeCurrentAndLast:
                        modifier = DATE_RANGE_MODIFIER_CURRENTAND_LAST;
                        break;
                    default:
                        modifier = DATE_RANGE_MODIFIER_CURRENT;
                }
                mOnComplete.onComplete(range, modifier);
                dismiss();
            }
        });
    }
}