Example usage for android.app AlertDialog.Builder show

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

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.hypodiabetic.happ.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    //xdrip start
    extendedGraphBuilder = new ExtendedGraphBuilder(getApplicationContext());

    _broadcastReceiver = new BroadcastReceiver() {
        @Override//from w ww  .j ava2  s  . c  o  m
        public void onReceive(Context ctx, Intent intent) {
            if (intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0) {
                setupBGCharts();
                displayCurrentInfo();
                holdViewport.set(0, 0, 0, 0);
            }
        }
    };
    newDataReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context ctx, Intent intent) {
            setupBGCharts();
            displayCurrentInfo();
            holdViewport.set(0, 0, 0, 0);
        }
    };
    registerReceiver(_broadcastReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
    registerReceiver(newDataReceiver, new IntentFilter(Intents.ACTION_NEW_BG));
    setupBGCharts();
    displayCurrentInfo();
    holdViewport.set(0, 0, 0, 0);
    //xdrip end

    //listens out for new Stats
    newStatsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
            Stats stat = gson.fromJson(intent.getStringExtra("stat"), Stats.class);

            updateStats(stat);
            displayCurrentInfo();
        }
    };
    registerReceiver(newStatsReceiver, new IntentFilter("ACTION_UPDATE_STATS"));
    updateStats(null);

    //listens out for openAPS updates
    newAPSUpdate = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
            APSResult apsResult = gson.fromJson(intent.getStringExtra("APSResult"), APSResult.class);

            updateOpenAPSDetails(apsResult);
            setupBGCharts();
            displayCurrentInfo();
        }
    };
    registerReceiver(newAPSUpdate, new IntentFilter("APS_UPDATE"));

    //listens out for app notifications
    appNotification = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int snackbar_length;
            snackbar_length = intent.getIntExtra("snackbar_length", Snackbar.LENGTH_INDEFINITE);
            final String alertDialogText = intent.getStringExtra("alertDialogText");
            String snackBarMsg = intent.getStringExtra("snackBarMsg");

            Snackbar snackbar = Snackbar
                    .make(MainActivity.activity.findViewById(R.id.mainActivity), snackBarMsg, snackbar_length)
                    .setAction("DETAILS", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.activity);
                            builder.setMessage(alertDialogText);
                            builder.setPositiveButton("OK", null);
                            builder.show();
                        }
                    });
            snackbar.show();

        }
    };
    registerReceiver(appNotification, new IntentFilter("NEW_APP_NOTIFICATION"));

}

From source file:org.starfishrespect.myconsumption.android.ui.CreateAccountActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_account);

    editTextUsername = (EditText) findViewById(R.id.editTextUsername);
    editTextPassword = (EditText) findViewById(R.id.editTextPassword);
    editTextPassword2 = (EditText) findViewById(R.id.editTextPassword2);
    buttonCreateAccount = (Button) findViewById(R.id.buttonCreateAccount);
    buttonCreateAccount.setOnClickListener(new View.OnClickListener() {
        @Override// w  w  w .  j  av a2 s  . co m
        public void onClick(View v) {
            if (!MiscFunctions.isOnline(CreateAccountActivity.this)) {
                MiscFunctions.makeOfflineDialog(CreateAccountActivity.this).show();
                return;
            }
            if (editTextUsername.getText().toString().equals("")
                    || editTextPassword.getText().toString().equals("")
                    || editTextPassword2.getText().toString().equals("")) {
                Toast.makeText(CreateAccountActivity.this,
                        getString(R.string.dialog_message_error_must_fill_all_fields), Toast.LENGTH_LONG)
                        .show();
                return;
            }

            if (!editTextPassword.getText().toString().equals(editTextPassword2.getText().toString())) {
                Toast.makeText(CreateAccountActivity.this, R.string.dialog_message_error_password_must_match,
                        Toast.LENGTH_LONG).show();
                return;
            }

            new AsyncTask<Void, Void, Integer>() {

                @Override
                protected Integer doInBackground(Void... params) {
                    return createAccount();
                }

                @Override
                protected void onPostExecute(Integer result) {
                    if (result == 0) {
                        setResult(RESULT_OK);
                        finish();
                    } else {
                        AlertDialog.Builder builder = new AlertDialog.Builder(CreateAccountActivity.this);
                        builder.setTitle(R.string.dialog_title_error);
                        builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                        switch (result) {
                        case SimpleResponseDTO.STATUS_ALREADY_EXISTS:
                            builder.setMessage(R.string.dialog_message_error_user_already_exists);
                            break;
                        default:
                            builder.setMessage("An error has occurred. You might want to "
                                    + "check your internet connection or contact the application provider.");
                            break;

                        }
                        builder.show();
                    }
                }
            }.execute();
        }
    });
}

From source file:com.andybotting.tubechaser.activity.Home.java

/**
 * Show about dialog window/*from   ww  w .j av a 2s  .  c o  m*/
 */
public void showAbout() {
    // Get the package name
    String heading = getResources().getText(R.string.app_name) + "\n";

    try {
        PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
        heading += "v" + pi.versionName + "\n\n";
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    // Build alert dialog
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle(heading);
    View aboutView = getLayoutInflater().inflate(R.layout.dialog_about, null);
    dialogBuilder.setView(aboutView);
    dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Set first launch flag in DB
            mPreferenceHelper.setFirstLaunchThisVersion();
        }
    });
    dialogBuilder.setCancelable(false);
    dialogBuilder.setIcon(R.drawable.appicon);
    dialogBuilder.show();
}

From source file:im.vector.util.BugReporter.java

/**
 * Send a bug report either with email or with Vector.
 *///from w w w . j a  va  2s .  c  o m
public static void sendBugReport() {
    final Activity currentActivity = VectorApp.getCurrentActivity();

    // no current activity so cannot display an alert
    if (null == currentActivity) {
        sendBugReport(VectorApp.getInstance().getApplicationContext(), true, true, "", null);
        return;
    }

    final Context appContext = currentActivity.getApplicationContext();
    LayoutInflater inflater = currentActivity.getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.dialog_bug_report, null);

    final AlertDialog.Builder dialog = new AlertDialog.Builder(currentActivity);
    dialog.setTitle(R.string.send_bug_report);
    dialog.setView(dialogLayout);

    final EditText bugReportText = (EditText) dialogLayout.findViewById(R.id.bug_report_edit_text);
    final CheckBox includeLogsButton = (CheckBox) dialogLayout
            .findViewById(R.id.bug_report_button_include_logs);
    final CheckBox includeCrashLogsButton = (CheckBox) dialogLayout
            .findViewById(R.id.bug_report_button_include_crash_logs);

    final ProgressBar progressBar = (ProgressBar) dialogLayout.findViewById(R.id.bug_report_progress_view);
    final TextView progressTextView = (TextView) dialogLayout.findViewById(R.id.bug_report_progress_text_view);

    dialog.setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // will be overridden to avoid dismissing the dialog while displaying the progress
        }
    });

    dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // will be overridden to avoid dismissing the dialog while displaying the progress
        }
    });

    //
    final AlertDialog bugReportDialog = dialog.show();
    final Button cancelButton = bugReportDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
    final Button sendButton = bugReportDialog.getButton(AlertDialog.BUTTON_POSITIVE);

    if (null != cancelButton) {
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // check if there is no upload in progress
                if (includeLogsButton.isEnabled()) {
                    bugReportDialog.dismiss();
                } else {
                    mIsCancelled = true;
                    cancelButton.setEnabled(false);
                }
            }
        });
    }

    if (null != sendButton) {
        sendButton.setEnabled(false);

        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable the active area while uploading the bug report
                bugReportText.setEnabled(false);
                sendButton.setEnabled(false);
                includeLogsButton.setEnabled(false);
                includeCrashLogsButton.setEnabled(false);

                progressTextView.setVisibility(View.VISIBLE);
                progressTextView.setText(appContext.getString(R.string.send_bug_report_progress, 0 + ""));

                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(0);

                sendBugReport(VectorApp.getInstance(), includeLogsButton.isChecked(),
                        includeCrashLogsButton.isChecked(), bugReportText.getText().toString(),
                        new IMXBugReportListener() {
                            @Override
                            public void onUploadFailed(String reason) {
                                try {
                                    if (null != VectorApp.getInstance() && !TextUtils.isEmpty(reason)) {
                                        Toast.makeText(VectorApp.getInstance(),
                                                VectorApp.getInstance()
                                                        .getString(R.string.send_bug_report_failed, reason),
                                                Toast.LENGTH_LONG).show();
                                    }
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadFailed() : failed to display the toast "
                                            + e.getMessage());
                                }

                                try {
                                    // restore the dialog if the upload failed
                                    bugReportText.setEnabled(true);
                                    sendButton.setEnabled(true);
                                    includeLogsButton.setEnabled(true);
                                    includeCrashLogsButton.setEnabled(true);
                                    cancelButton.setEnabled(true);

                                    progressTextView.setVisibility(View.GONE);
                                    progressBar.setVisibility(View.GONE);
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadFailed() : failed to restore the dialog button "
                                            + e.getMessage());

                                    try {
                                        bugReportDialog.dismiss();
                                    } catch (Exception e2) {
                                        Log.e(LOG_TAG, "## onUploadFailed() : failed to dismiss the dialog "
                                                + e2.getMessage());
                                    }
                                }

                                mIsCancelled = false;
                            }

                            @Override
                            public void onUploadCancelled() {
                                onUploadFailed(null);
                            }

                            @Override
                            public void onProgress(int progress) {
                                if (progress > 100) {
                                    Log.e(LOG_TAG, "## onProgress() : progress > 100");
                                    progress = 100;
                                } else if (progress < 0) {
                                    Log.e(LOG_TAG, "## onProgress() : progress < 0");
                                    progress = 0;
                                }

                                progressBar.setProgress(progress);
                                progressTextView.setText(
                                        appContext.getString(R.string.send_bug_report_progress, progress + ""));
                            }

                            @Override
                            public void onUploadSucceed() {
                                try {
                                    if (null != VectorApp.getInstance()) {
                                        Toast.makeText(VectorApp.getInstance(),
                                                VectorApp.getInstance().getString(
                                                        R.string.send_bug_report_sent),
                                                Toast.LENGTH_LONG).show();
                                    }
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the toast "
                                            + e.getMessage());
                                }

                                try {
                                    bugReportDialog.dismiss();
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the dialog "
                                            + e.getMessage());
                                }
                            }
                        });
            }
        });
    }

    bugReportText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (null != sendButton) {
                sendButton.setEnabled(bugReportText.getText().toString().length() > 10);
            }
        }

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

From source file:com.example.drugsformarinemammals.Combined_Search.java

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);//from  w  w w .  j  ava 2 s  .  c  o  m
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText(messageTitle);
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}

From source file:com.getkickbak.plugin.NotificationPlugin.java

/**
 * Builds and shows a native Android alert with given Strings
 * /*from w  ww .  java 2 s  .c o  m*/
 * @param message
 *           The message the alert should display
 * @param title
 *           The title of the alert
 * @param buttonLabel
 *           The label of the button
 * @param callbackContext
 *           The callback context
 */
public synchronized void alert(final String message, final String title, final String buttonLabel,
        final CallbackContext callbackContext) {

    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {
        public void run() {

            AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(true);
            dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });

            dlg.create();
            dlg.show();
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:net.evecom.android.log.DailyLogAddActivity.java

/**
 * /*from  w  w w. ja  v  a 2 s . c  om*/
 */
private String submit() {
    /**  */
    if (btEditText.getText().toString().trim().length() < 1) {
        DialogToast("");
        return "";
    } else if (sswgButton.getText().toString().trim().length() < 1) {
        DialogToast("");
        return "";
    } else if (rzlxButton.getText().toString().trim().length() < 1) {
        DialogToast("");
        return "";
    } else if (gzsjButton.getText().toString().trim().length() < 1) {
        DialogToast("");
        return "";
    } else if (rznrEditText.getText().toString().trim().length() < 1) {
        DialogToast("");
        return "";
    } else if (years > calendar.get(Calendar.YEAR)) {
        DialogToast("");
        return "";
    } else if (years == calendar.get(Calendar.YEAR)) {
        if (month > calendar.get(Calendar.MONTH) + 1) {
            DialogToast("");
            return "";
        } else if (month == calendar.get(Calendar.MONTH) + 1) {
            if (day > calendar.get(Calendar.DAY_OF_MONTH)) {
                DialogToast("");
                return "";
            }
        }
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(DailyLogAddActivity.this);
    builder.setTitle("");
    builder.setIcon(R.drawable.qq_dialog_default_icon);// 
    builder.setMessage("");
    builder.setPositiveButton("", new DialogInterface.OnClickListener() {
        // @Override
        public void onClick(DialogInterface dialog, int which) {
            progressDialog = ProgressDialog.show(DailyLogAddActivity.this, "", "...");

            formSubmit();

        }
    });
    builder.setNegativeButton("", new DialogInterface.OnClickListener() {
        // @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.show();
    return "1";
}

From source file:app.CT.BTCCalculator.fragments.BreakevenFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Register Bus Provider instance.
    BusProvider.getInstance().register(this);

    View view = getView();//from  w  ww.j  av  a 2s .c om

    // Initialize text fields.
    assert view != null;
    btcBought = (EditText) view.findViewById(R.id.btcBought);
    btcBoughtPrice = (EditText) view.findViewById(R.id.btcBoughtPrice);
    btcSold = (EditText) view.findViewById(R.id.btcSold);
    btcSoldPrice = (EditText) view.findViewById(R.id.btcSoldPrice);
    optimalBTCPrice = (EditText) view.findViewById(R.id.optimalBTCPrice);
    optimalBTC = (EditText) view.findViewById(R.id.optimalBTC);
    resultText = (TextView) view.findViewById(R.id.resultText);

    Button buttonCalculate = (Button) view.findViewById(R.id.buttonCalculate);

    // Checks whether the first visible EditText element is focused in order to enable
    // and show the keyboard to the user. The corresponding XML element has android:imeOptions="actionNext".
    // All EditText elements below are now programmed to show keyboard when pressed.
    btcBought.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcBoughtPrice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcSold.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcSoldPrice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    optimalBTCPrice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    optimalBTC.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    optimalBTCPrice.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                float result = ((Float.valueOf(btcSold.getText().toString()))
                        * Float.valueOf(btcSoldPrice.getText().toString()))
                        / Float.valueOf(optimalBTCPrice.getText().toString());
                optimalBTC.setText(String.valueOf(result));
            } catch (Exception ignored) {
            }

        }
    });

    btcBoughtPrice.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            containsCurrentRate[0] = false;
        }
    });

    btcSoldPrice.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            containsCurrentRate[1] = false;
        }
    });

    buttonCalculate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            float buyAmount, buyCost, sellAmount, sellPrice, optimalBTCCost, optimalBTCAmount, remainder,
                    totalCost, totalAmount, finalPrice;
            boolean didItWork = true;
            boolean validTransaction = true;

            // Error checking to prevent crashes.
            try {
                // Gets the input entered from the user.
                buyAmount = Float.valueOf(btcBought.getText().toString());
                buyCost = Float.valueOf(btcBoughtPrice.getText().toString());
                sellAmount = Float.valueOf(btcSold.getText().toString());
                sellPrice = Float.valueOf(btcSoldPrice.getText().toString());
                optimalBTCCost = Float.valueOf(optimalBTCPrice.getText().toString());
                optimalBTCAmount = Float.valueOf(optimalBTC.getText().toString());

                // Calculates remainder from the buying and selling.
                remainder = Math.abs((buyAmount - sellAmount));

                // User cannot sell more than they own.
                if (roundTwoDecimals(optimalBTCAmount * optimalBTCCost) > roundTwoDecimals(
                        sellAmount * sellPrice)) {
                    final android.support.v7.app.AlertDialog.Builder alertDialog = new android.support.v7.app.AlertDialog.Builder(
                            getActivity());
                    alertDialog.setTitle("Error");
                    alertDialog.setMessage(getString(R.string.optimalBTCErrorMsg));
                    alertDialog.setCancelable(false);
                    alertDialog.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    alertDialog.show();
                    validTransaction = false;
                }

                // Checks if the user typed in a greater selling amount than buying.
                if (sellAmount > buyAmount) {
                    // Create new dialog popup.
                    final android.support.v7.app.AlertDialog.Builder alertDialog = new android.support.v7.app.AlertDialog.Builder(
                            getActivity());

                    alertDialog.setTitle("Error");
                    alertDialog.setMessage("You cannot sell more than you own.");
                    alertDialog.setCancelable(false);
                    alertDialog.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // If this button is clicked, close current dialog.
                            dialog.cancel();
                        }
                    });
                    alertDialog.show();

                    // Invalidates transaction since selling amount > buying amount.
                    validTransaction = false;
                }

                // Calculations to output.
                totalCost = buyAmount * buyCost;
                totalAmount = optimalBTCAmount + remainder;
                finalPrice = totalCost / totalAmount;

                if (validTransaction) {
                    resultText.setText(String.format(getString(R.string.resultText),
                            String.valueOf(totalAmount), String.valueOf(roundTwoDecimals(finalPrice))));
                }
            } catch (Exception e) {
                // Sets bool to false in order to execute "finally" block below.
                didItWork = false;
            } finally {
                if (!didItWork) {
                    // Creates new dialog popup.
                    final AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(getActivity());

                    alertDialog2.setTitle("Error");
                    alertDialog2.setMessage("Please fill in all fields.");
                    alertDialog2.setCancelable(false);
                    alertDialog2.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // If this button is clicked, close current dialog.
                            dialog.cancel();
                        }
                    });

                    // Show the dialog.
                    alertDialog2.show();
                }
            }

        }
    });
}

From source file:tcc.iesgo.activity.ClientMapActivity.java

@Override
public void onProviderDisabled(String arg0) {
    final AlertDialog.Builder dialog = new AlertDialog.Builder(getParent());
    dialog.setTitle(getString(R.string.gps_disabled));
    dialog.setMessage(getString(R.string.gps_disabled_message));
    dialog.setIcon(R.drawable.gps_enable);
    dialog.setCancelable(false);/*from  w  w  w . j  a  v  a 2s  . c om*/

    dialog.setPositiveButton(getString(R.string.ad_button_positive), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
    });

    dialog.setNegativeButton(getString(R.string.ad_button_negative), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
            finish();
        }
    });
    dialog.show();
}

From source file:at.jclehner.rxdroid.DrugEditFragment.java

private void showDrugDiscardDialog() {
    final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
    ab.setMessage(R.string._msg_err_empty_drug_name);
    ab.setNegativeButton(android.R.string.cancel, null);
    ab.setPositiveButton(android.R.string.ok, new OnClickListener() {

        @Override/*from w w w  . j  a  va  2s . c  om*/
        public void onClick(DialogInterface dialog, int which) {
            getActivity().finish();
        }
    });

    ab.show();
}