Example usage for android.app AlertDialog setButton

List of usage examples for android.app AlertDialog setButton

Introduction

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

Prototype

public void setButton(int whichButton, CharSequence text, OnClickListener listener) 

Source Link

Document

Set a listener to be invoked when the positive button of the dialog is pressed.

Usage

From source file:edu.rutgers.winlab.crowdpp.ui.MainActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // exit the app
    case R.id.exit:
        Toast.makeText(this, "Closing...", Toast.LENGTH_SHORT).show();
        //System.exit(0);
        this.finish();
        break;//from   w w w .ja  va 2s  .c o  m
    // show the FAQ 
    case R.id.help:
        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle("FAQ");
        dialog.setMessage(Constants.FAQ);
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Close", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.show();
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(20);
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.google.cast.samples.games.spellcast.MainActivity.java

/**
 * Shows an error dialog./*  www .  j  av a 2 s.c o  m*/
 *
 * @param errorMessage The message to show in the dialog.
 */
private void showErrorDialog(final String errorMessage) {
    if (!isDestroyed()) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // Show a error dialog along with error messages.
                AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
                alertDialog.setTitle(getString(R.string.game_connection_error_message));
                alertDialog.setMessage(errorMessage);
                alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL,
                        getString(R.string.game_dialog_ok_button_text), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                alertDialog.show();
            }
        });
    }
}

From source file:com.swissbit.homeautomation.asyncTask.AuthenticationAsync.java

/**
 *Show the dialog message after the RaspberryPi authentication
 *//*w ww .  j ava  2 s .  com*/
public void showDialog() {
    AlertDialog alertDialog = new AlertDialog.Builder(mainActivityContext).create();
    alertDialog.setTitle("Information");
    alertDialog.setMessage(dialogMessage);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (subscriptionResponse)
                mainActivity.checkRaspberryId(rid);
            dialog.dismiss();
            cancel(true);
        }
    });
    alertDialog.show();
}

From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java

public boolean checkStackTrace() {
    FileInputStream traceIn = null;
    try {//  ww w  .  j  a  va  2 s . co  m
        traceIn = openFileInput("stack.trace");
        traceIn.close();
    } catch (FileNotFoundException fnfe) {
        // No stack trace available
        return false;
    } catch (IOException ioe) {
        return false;
    }

    AlertDialog alert = new AlertDialog.Builder(this).create();
    alert.setMessage(getResources().getString(R.string.crashreport_msg));

    alert.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.emailstr),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    String trace = "";
                    String line = null;
                    try {
                        BufferedReader reader = new BufferedReader(
                                new InputStreamReader(TwitSpeakActivity.this.openFileInput("stack.trace")));
                        while ((line = reader.readLine()) != null) {
                            trace += line + "\n";
                        }
                    } catch (FileNotFoundException fnfe) {
                        Log.logException(TAG, fnfe);
                    } catch (IOException ioe) {
                        Log.logException(TAG, ioe);
                    }

                    Intent sendIntent = new Intent(Intent.ACTION_SEND);
                    String subject = "Error report";
                    String body = getResources().getString(R.string.mailthisto_msg) + " jayesh@altcanvas.com: "
                            + "\n\n" + G.getPhoneInfo() + "\n\n" + "TwitSpeak [" + G.VERSION_STRING + "]"
                            + "\n\n" + trace + "\n\n";

                    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "jayesh@altcanvas.com" });
                    sendIntent.putExtra(Intent.EXTRA_TEXT, body);
                    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    sendIntent.setType("message/rfc822");

                    TwitSpeakActivity.this.startActivityForResult(
                            Intent.createChooser(sendIntent, getResources().getString(R.string.emailstr)),
                            G.REQCODE_EMAIL_STACK_TRACE);

                    TwitSpeakActivity.this.deleteFile("stack.trace");
                }
            });
    alert.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancelstr),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    TwitSpeakActivity.this.deleteFile("stack.trace");
                    TwitSpeakActivity.this.continueOnCreate();
                }
            });

    alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            TwitSpeakActivity.this.deleteFile("stack.trace");
            TwitSpeakActivity.this.continueOnCreate();
        }
    });

    alert.show();

    return true;
}

From source file:com.telestax.restcomm_olympus.MainFragment.java

private void showOkAlert(final String title, final String detail) {
    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
    alertDialog.setTitle(title);/*from w w  w .ja v  a 2  s . c o m*/
    alertDialog.setMessage(detail);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alertDialog.show();
}

From source file:com.jwork.dhammapada.MainActivity.java

private void showCrashDialog() {
    final CrashHandler handler = CrashHandler.getInstance();
    final AlertDialog ad = new AlertDialog.Builder(this).create();
    ad.setTitle("Error Report");
    ad.setMessage("An error was detected. Reporting it will support faster bug fixing.");
    ad.setButton(AlertDialog.BUTTON_POSITIVE, "Report it", new DialogInterface.OnClickListener() {

        @Override/*w w w  .j  a v a2s .  c  om*/
        public void onClick(DialogInterface dialog, int which) {
            handler.clearCrashFlag();
            ad.dismiss();
            MainActivity.this.finish();
            handler.sendEmail(MainActivity.this);
            //            MainActivity.this.startActivity(new Intent(MainActivity.this, MainActivity.class));
        }
    });
    ad.setButton(AlertDialog.BUTTON_NEGATIVE, "Not now", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            handler.clearCrashFlag();
            ad.dismiss();
            MainActivity.this.finish();
            MainActivity.this.startActivity(new Intent(MainActivity.this, MainActivity.class));
        }
    });
    ad.show();
}

From source file:es.uja.photofirma.android.SignUpActivity.java

/**
 * Advertencia a cerca de la privacidad del usuario, el usuario ser notificado
 * //from   ww w .j  a  va  2 s.  c om
 */
public void onTermsOfUse(View view) {
    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Terminos de uso");
    alertDialog.setMessage(getString(R.string.terms_of_use));
    alertDialog.setCancelable(false);
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss();
        }
    });
    alertDialog.show();

}

From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java

private void promptTTSInstall() {
    AlertDialog ttsInstallDlg = new AlertDialog.Builder(this).create();
    ttsInstallDlg.setMessage(getString(R.string.tts_install_msg));
    ttsInstallDlg.setTitle(getString(R.string.tts_install_title));

    ttsInstallDlg.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.proceed_str),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();//from ww  w  . j  av a  2  s  .c  o m
                    Intent installIntent = new Intent();
                    installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                    startActivity(installIntent);
                }
            });

    ttsInstallDlg.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel_str),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                    finish();
                }
            });
}

From source file:org.jonblack.bluetrack.activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    // Load default preference values.
    // The defaults are only loaded if they haven't been done before. It will
    // not overwrite changes.
    // @see PreferenceManager.setDefaultValues
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Get the local bluetooth adapter and check if bluetooth is supported.
    BluetoothAdapter localBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (localBtAdapter == null) {
        Log.w(TAG, "Bluetooth isn't supported on device.");

        AlertDialog ad = new AlertDialog.Builder(this).create();
        ad.setCancelable(false);/*from  w  w w .ja  va 2  s.  c om*/
        Resources r = getResources();
        String msg = r.getString(R.string.error_bluetooth_not_supported, r.getString(R.string.app_name));
        ad.setMessage(msg);
        ad.setButton(AlertDialog.BUTTON_POSITIVE, r.getString(R.string.button_exit),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                        dialog.dismiss();
                    }
                });
        ad.show();

        return;
    }

    Resources r = getResources();

    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ActionBar.Tab tab1 = actionBar.newTab().setText(r.getText(R.string.ab_tab_live_tracking));
    tab1.setTag("tracking");
    tab1.setTabListener(new TabListener<LiveTrackingFragment>(this, "tracking", LiveTrackingFragment.class));
    actionBar.addTab(tab1);

    ActionBar.Tab tab2 = actionBar.newTab().setText(r.getText(R.string.ab_tab_sessions));
    tab2.setTag("session");
    tab2.setTabListener(new TabListener<SessionFragment>(this, "session", SessionFragment.class));
    actionBar.addTab(tab2);

    ActionBar.Tab tab3 = actionBar.newTab().setText(r.getText(R.string.ab_tab_devices));
    tab3.setTag("devices");
    tab3.setTabListener(new TabListener<DevicesFragment>(this, "devices", DevicesFragment.class));
    actionBar.addTab(tab3);
}

From source file:com.metinkale.prayerapp.vakit.fragments.SortFragment.java

public void onItemDismiss(final int position) {
    final Times times = Times.getTimesAt(position);

    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
    dialog.setTitle(R.string.delete);/* w  w  w.  java  2  s.c o  m*/
    dialog.setMessage(getString(R.string.delConfirm, times.getName()));
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int buttonId) {
                    times.delete();
                    mAdapter.notifyItemRemoved(position);
                }
            });
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int buttonId) {
                    dialog.cancel();
                    mAdapter.notifyDataSetChanged();
                }
            });
    dialog.show();
}