Example usage for android.app AlertDialog.Builder setView

List of usage examples for android.app AlertDialog.Builder setView

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setView.

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:Main.java

public static AlertDialog.Builder dialogBuilder(Context context, int title, View view) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (view != null) {
        builder.setView(view);
    }/* w  w w  .j  a v a  2 s  . c  om*/
    if (title > 0) {
        builder.setTitle(title);
    }
    return builder;
}

From source file:Main.java

public static AlertDialog.Builder createAlertDialog(Context context, String title, View dialogView) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);/*from w w w.  java  2 s  . c o m*/
    builder.setCancelable(false);
    builder.setView(dialogView);
    return builder;
}

From source file:Main.java

/**
 * @param context : the context that the dialog interface will be binded to
 * @param title :  dialog title/*  ww  w  .j  a  v a 2s .  c  o m*/
 * @param positiveButtonText
 * @param positiveListener
 * @param negativeButtonText
 * @param negativeListener
 * @param neutralButtonText
 * @param neutralListener
 * @param content : Custom View for the dialog
 */
public static void showDialog(Context context, String title, String positiveButtonText,
        OnClickListener positiveListener, String negativeButtonText, OnClickListener negativeListener,
        String neutralButtonText, OnClickListener neutralListener, View content) {
    if (alert != null)
        hideDialog();

    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    if (content != null)
        builder.setView(content);

    builder.setMessage(title).setCancelable(false);

    if (negativeButtonText != null && negativeListener != null)
        builder.setNegativeButton(negativeButtonText, negativeListener);
    else
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

            }
        });

    if (positiveButtonText != null && positiveListener != null) {

        builder.setPositiveButton(positiveButtonText, positiveListener);
    }
    if (neutralButtonText != null && neutralListener != null)
        builder.setNeutralButton(neutralButtonText, neutralListener);
    alert = builder.create();

    alert.show();

}

From source file:com.wellsandwhistles.android.redditsp.common.DialogUtils.java

public static void showSearchDialog(Context context, int titleRes, final OnSearchListener listener) {
    final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
    final EditText editText = (EditText) LayoutInflater.from(context).inflate(R.layout.dialog_editbox, null);

    alertBuilder.setView(editText);
    alertBuilder.setTitle(titleRes);/*from w  w w . java 2s .co m*/

    alertBuilder.setPositiveButton(R.string.action_search, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String query = General.asciiLowercase(editText.getText().toString()).trim();
            if (StringUtils.isEmpty(query)) {
                listener.onSearch(null);
            } else {
                listener.onSearch(query);
            }
        }
    });

    alertBuilder.setNegativeButton(R.string.dialog_cancel, null);

    final AlertDialog alertDialog = alertBuilder.create();
    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    alertDialog.show();
}

From source file:Main.java

/**
 * Shows a Dialog with a title, a message, a EditText and two Buttons for OK
 * and Cancel. The user can't click OK when the EditText is empty.
 *
 * @param context/*from   w  w  w  .  ja v a2  s. co  m*/
 *            The Context of the calling Activity
 * @param title
 *            Title of the Dialog
 * @param message
 *            Message of the Dialog
 * @param inputEditText
 *            The EditText used for this Dialog. You can modify it for
 *            example by setting the input type before passing it to this
 *            method. You can also read the text from the calling method.
 * @param onOkClickListener
 *            The Listener for clicking on the OK button.
 */
public static void showDialog(Context context, String title, String message, EditText inputEditText,
        DialogInterface.OnClickListener onOkClickListener) {

    AlertDialog.Builder alert = new AlertDialog.Builder(context);
    alert.setTitle(title);
    alert.setMessage(message);
    alert.setView(inputEditText);

    /*
     * OK button
     */
    alert.setPositiveButton(context.getString(android.R.string.ok), onOkClickListener);
    /*
     * Cancel button
     */
    alert.setNegativeButton(context.getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            /*
             * Canceled.
             */
        }
    });

    final AlertDialog dialog = alert.show();
    if (dialog != null) {
        /*
         * Disable ok button.
         */
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
        /*
         * Dis- and enable , dependent on the text entered
         */
        inputEditText.addTextChangedListener(new TextWatcher() {
            /**
             * Enable OK button if text entered, disable otherwise.
             */
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                dialog.getButton(DialogInterface.BUTTON_POSITIVE)
                        .setEnabled(!s.toString().equals("") && isValideUrl(s.toString()));
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void afterTextChanged(Editable s) {
            }
        });
    }
}

From source file:com.otaupdater.utils.UserUtils.java

public static void showLoginDialog(final Context ctx, String defUsername, final DialogCallback dlgCallback,
        final LoginCallback loginCallback) {
    @SuppressLint("InflateParams")
    View view = LayoutInflater.from(ctx).inflate(R.layout.login_dialog, null);
    if (view == null)
        return;//from w w w .ja  va  2 s . c  o m
    final EditText inputUsername = (EditText) view.findViewById(R.id.auth_username);
    final EditText inputPassword = (EditText) view.findViewById(R.id.auth_password);

    if (defUsername != null)
        inputUsername.setText(defUsername);

    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle(R.string.alert_login_title);
    builder.setView(view);
    builder.setPositiveButton(R.string.login, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            /* set below */ }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (loginCallback != null)
                loginCallback.onCancel();
        }
    });

    final AlertDialog dlg = builder.create();
    dlg.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            if (dlgCallback != null)
                dlgCallback.onDialogShown(dlg);
            Button button = dlg.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button == null)
                return;
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final String username = inputUsername.getText().toString();
                    final String password = inputPassword.getText().toString();

                    if (username.length() == 0 || password.length() == 0) {
                        Toast.makeText(ctx, R.string.toast_blank_userpass_error, Toast.LENGTH_LONG).show();
                        return;
                    }

                    dlg.dismiss();

                    APIUtils.userLogin(ctx, username, password, new APIUtils.ProgressDialogAPICallback(ctx,
                            ctx.getString(R.string.alert_logging_in), dlgCallback) {
                        @Override
                        public void onSuccess(String message, JSONObject respObj) {
                            try {
                                String realUsername = respObj.getString("username");
                                String hmacKey = respObj.getString("key");
                                Config.getInstance(ctx).storeLogin(realUsername, hmacKey);
                                if (loginCallback != null)
                                    loginCallback.onLoggedIn(realUsername);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onError(String message, JSONObject respObj) {
                            //TODO show some error
                        }
                    });
                }
            });
        }
    });
    dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (dlgCallback != null)
                dlgCallback.onDialogClosed(dlg);
        }
    });
    dlg.show();
}

From source file:com.fuzz.android.limelight.model.ChapterTransition.java

public static void getDrawerPosition() {
    LayoutInflater inflater = LimeLight.getActivity().getLayoutInflater();
    View drawerView = inflater.inflate(R.layout.choose_drawer_item, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(LimeLight.getActivity());
    builder.setTitle(R.string.choose_drawer_item);
    builder.setView(drawerView);

    final Spinner positionSpinner = (Spinner) drawerView.findViewById(R.id.positionSpinner);

    ArrayList<String> items = new ArrayList<String>();
    for (int i = 0; i < LimeLight.getDrawerList().getAdapter().getCount(); i++) {
        items.add(i + "");
    }/* ww w.ja v a  2  s  . co  m*/

    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(LimeLight.getActivity(),
            android.R.layout.simple_spinner_dropdown_item, items);

    positionSpinner.setAdapter(spinnerArrayAdapter);

    positionSpinner.setSelection(mDrawerItemPosition);

    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mDrawerItemPosition = Integer.valueOf(positionSpinner.getSelectedItem().toString());
        }
    });

    builder.setNegativeButton(R.string.cancel, null);

    builder.create();
    builder.show();
}

From source file:Main.java

public static AlertDialog.Builder getAlertDialogWithTwoButtonAndEditView(Context context, String message,
        String positiveBtnLabel, String negetiveBtnLabel, DialogInterface.OnClickListener positiveClickListener,
        DialogInterface.OnClickListener negativeClickListener, EditText input) {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message).setPositiveButton(positiveBtnLabel, positiveClickListener)
            .setNegativeButton(negetiveBtnLabel, negativeClickListener);

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    input.setLayoutParams(lp);/*from   w  ww.  ja  va  2 s .c  o m*/
    builder.setView(input);

    return builder;
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static void setupOnLinkClick(final Context context, final String url, final TextView textView) {
    textView.setOnClickListener(new View.OnClickListener() {
        @Override//from  w w w.j av a2  s  .c o m
        public void onClick(View v) {
            AlertDialog.Builder imageDialog = new AlertDialog.Builder(context);
            ProgressBar progressBar = new ProgressBar(context);
            imageDialog.setView(progressBar);
            AlertDialog progressDialog = imageDialog.create();
            progressDialog.show();
            new GetImageAsyncTask(new AsyncTaskCompletionNotifierImagePopup(context, progressDialog))
                    .execute(url);
        }
    });
}

From source file:com.bt.download.android.gui.util.UIUtils.java

public static void showOkCancelDialog(Context context, View view, int titleId, OnClickListener okListener,
        OnClickListener cancelListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    builder.setView(view).setTitle(titleId).setPositiveButton(android.R.string.ok, okListener)
            .setNegativeButton(android.R.string.cancel, cancelListener);

    builder.create().show();/*from  w w  w. j  av  a  2s  .  c  o  m*/
}