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:com.glanznig.beepme.view.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    BeeperApp app = (BeeperApp) getApplication();

    switch (item.getItemId()) {
    case R.id.action_toggle_beeper:
        if (app.isBeeperActive()) {
            app.cancelTimer(); //call before setBeeperActive
            app.setBeeperActive(BeeperApp.BEEPER_INACTIVE);
            item.setIcon(R.drawable.ic_menu_beeper_off);

            // hide generate beep menu entry
            if (this.actionMenu != null && app.getPreferences().isTestMode()) {
                MenuItem testBeep = actionMenu.findItem(R.id.action_test_beep);
                testBeep.setVisible(false);
            }//w  w  w .j  ava  2s  .  com
        } else {
            app.setBeeperActive(BeeperApp.BEEPER_ACTIVE);
            app.setTimer();
            item.setIcon(R.drawable.ic_menu_beeper_on);

            // show generate beep menu entry
            if (this.actionMenu != null && app.getPreferences().isTestMode()) {
                MenuItem testBeep = actionMenu.findItem(R.id.action_test_beep);
                testBeep.setVisible(true);
            }
        }

        return true;

    case R.id.action_test_beep:
        app.beep();
        return true;

    case R.id.action_export:
        Intent iExport = new Intent(this, ExportActivity.class);
        startActivity(iExport);
        return true;

    case R.id.action_settings:
        Intent iSettings = new Intent(this, SettingsActivity.class);
        startActivity(iSettings);
        return true;

    case R.id.action_about:

        // thanks to F-Droid for the inspiration
        View view = null;
        LayoutInflater inflater = LayoutInflater.from(this);
        view = inflater.inflate(R.layout.about, null);

        try {
            PackageInfo pkgInfo = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(),
                    0);
            ((TextView) view.findViewById(R.id.about_version)).setText(pkgInfo.versionName);
        } catch (Exception e) {
        }

        AlertDialog.Builder alertBuilder = null;
        alertBuilder = new AlertDialog.Builder(this).setView(view);

        AlertDialog dia = alertBuilder.create();
        dia.setIcon(R.drawable.ic_launcher_beepme);
        dia.setTitle(getString(R.string.about_title));
        dia.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.about_donate_button),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Uri uri = Uri.parse("http://beepme.yourexp.at/support-beepme");
                        startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    }
                });

        dia.setButton(AlertDialog.BUTTON_NEGATIVE, getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
        dia.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:cz.muni.fi.japanesedictionary.fragments.AnkiFragmentAlertDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int title = getArguments().getInt("title");
    int message = getArguments().getInt("message");
    boolean onlyNegative = getArguments().getBoolean("onlyNegative", false);

    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setIcon(R.drawable.alert_dialog_icon)
            .setTitle(title).setMessage(message)
            .setNegativeButton(R.string.storno, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                }/*from w  w  w.  j av a 2 s  . c om*/
            }).create();
    if (!onlyNegative) {
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.download),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse("market://details?id=com.ichi2.anki"));
                        startActivity(intent);
                    }
                });
    }

    return alertDialog;

}

From source file:org.sigimera.app.android.MainActivity.java

/**
 * Shows the about dialog.//from  w ww  . jav a 2s  .c  o  m
 */
public final void showAboutDialog() {
    AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create();
    dialog.setTitle("About");
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            dialog.cancel();
        }
    });

    WebView wv = new WebView(this);
    wv.setBackgroundColor(Color.BLACK);

    StringBuffer strbuffer = new StringBuffer();
    strbuffer.append("<small><font color='white'>");
    strbuffer.append("<h3 style='text-align: center'>" + this.getString(R.string.app_name) + "</h3>");

    strbuffer.append("<p>This is the official App of the Crises "
            + "Information Platform Sigimera. It provides " + "the following functionality:</p>");
    strbuffer.append("<ul>");
    strbuffer.append("<li>Get crises (natural disaster) information."
            + "Currently floods, earthquakes, cyclones " + "and volcanic erruptions.</li>");
    strbuffer.append("<li>Get crises alerts via push notifications.</li>");
    strbuffer.append("<li>Get new crises via push notifications.</li>");
    strbuffer.append("<li>Manage your App via " + "<a href='http://www.sigimera.org/mobile_devices'>"
            + "<span style='color: #00FFFF'>mobile device management" + "website </span></a>.");
    strbuffer.append("</ul>");
    strbuffer.append("<p>&copy; 2013 <a href='http://www.sigimera.com'>"
            + "<span style='color: #00FFFF'>Sigimera Ltd.</span></a>. " + "All rights reserved.</p>");

    wv.loadData(strbuffer.toString(), "text/html", "utf-8");

    dialog.setView(wv);
    dialog.show();
}

From source file:com.clearcenter.mobile_demo.mdMainActivity.java

public void onCreate(Bundle bundle) {
    Log.i(TAG, "onCreate(" + bundle + ")");
    super.onCreate(bundle);

    setContentView(R.layout.main_activity);

    Log.i(TAG, "loading data from Intent");
    final Intent intent = getIntent();
    Log.i(TAG, "onCreate intent: " + intent);
    final Bundle extras = getIntent().getExtras();
    Log.i(TAG, "onCreate intent extras: " + extras);

    accounts_textview = (TextView) findViewById(R.id.accounts_textview);
    accounts_listview = (ListView) findViewById(R.id.accounts_listview);
    accounts_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1);
    accounts_listview.setAdapter(accounts_adapter);
    accounts_listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                final Intent intent = new Intent(mdMainActivity.this, mdAuthenticatorActivity.class);
                mdMainActivity.this.startActivity(intent);
                //new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT), 0);
            } else {
                final Intent intent = new Intent(mdMainActivity.this, mdStatusActivity.class);
                intent.putExtra("nickname", mdMainActivity.this.accounts_adapter.getItem(position));
                mdMainActivity.this.startActivity(intent);
            }//  ww w.j av  a 2s  .co  m
        }
    });

    accounts_listview.setOnItemLongClickListener(new OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0)
                return false;
            final String nickname = mdMainActivity.this.accounts_adapter.getItem(position);
            mdMainActivity.this.account_to_delete = nickname;
            AlertDialog alert_dialog = new AlertDialog.Builder(mdMainActivity.this).create();
            //alert_dialog.setIcon(R.drawable.ic_launcher);
            alert_dialog.setTitle("Remove System?");
            alert_dialog.setMessage("Are you sure you want to remove the " + nickname + " system account?");
            alert_dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Remove system",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            mdMainActivity.this.onRemoveAccount();
                        }
                    });
            alert_dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });

            alert_dialog.show();
            return true;
        }
    });

    account_manager = AccountManager.get(this);
}

From source file:cz.muni.fi.japanesedictionary.fragments.DictionaryFragmentAlertDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int title = getArguments().getInt("title");
    int message = getArguments().getInt("message");
    boolean onlyNegative = getArguments().getBoolean("onlyNegative", false);

    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
            .setNegativeButton(R.string.storno, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ((MainActivity) getActivity()).doNegativeClick();
                }/*  w  ww  .  ja v  a 2 s . c o m*/
            }).create();
    if (!onlyNegative) {
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.download),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        ((MainActivity) getActivity()).doPositiveClick();
                    }
                });
    }
    return alertDialog;

}

From source file:cz.muni.fi.japanesedictionary.fragments.MyFragmentAlertDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int title = getArguments().getInt("title");
    int message = getArguments().getInt("message");
    boolean onlyNegative = getArguments().getBoolean("onlyNegative", false);

    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
            .setNegativeButton(R.string.storno, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ((MainActivity) getActivity()).doNegativeClick();
                }//from   w w w .j a v a 2 s.  c o m
            }).create();
    if (!onlyNegative) {
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.download),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        ((MainActivity) getActivity()).doPositiveClick();
                    }
                });
    }

    return alertDialog;

}

From source file:com.yeldi.yeldibazaar.ManageRepo.java

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {

    super.onMenuItemSelected(featureId, item);
    LayoutInflater li = LayoutInflater.from(this);

    switch (item.getItemId()) {
    case ADD_REPO:
        View view = li.inflate(R.layout.addrepo, null);
        Builder p = new AlertDialog.Builder(this).setView(view);
        final AlertDialog alrt = p.create();

        alrt.setIcon(android.R.drawable.ic_menu_add);
        alrt.setTitle(getString(R.string.repo_add_title));
        alrt.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.repo_add_add),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        EditText uri = (EditText) alrt.findViewById(R.id.edit_uri);
                        String uri_str = uri.getText().toString();
                        try {
                            DB db = DB.getDB();
                            db.addRepo(uri_str, null, null, 10, null, true);
                        } finally {
                            DB.releaseDB();
                        }/*from w  w  w .  j  av a 2 s  .  com*/
                        changed = true;
                        redraw();
                    }
                });

        alrt.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
        alrt.show();
        return true;

    case REM_REPO:
        final List<String> rem_lst = new ArrayList<String>();
        CharSequence[] b = new CharSequence[repos.size()];
        for (int i = 0; i < repos.size(); i++) {
            b[i] = repos.get(i).address;
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.repo_delete_title));
        builder.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
        builder.setMultiChoiceItems(b, null, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
                if (isChecked) {
                    rem_lst.add(repos.get(whichButton).address);
                } else {
                    rem_lst.remove(repos.get(whichButton).address);
                }
            }
        });
        builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                try {
                    DB db = DB.getDB();
                    removeRepos(rem_lst);
                } finally {
                    DB.releaseDB();
                }
                changed = true;
                redraw();
            }
        });
        builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                return;
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
        return true;
    }
    return true;
}

From source file:org.restcomm.android.olympus.MainFragment.java

private void showOkAlert(final String title, final String detail) {
    AlertDialog alertDialog = new AlertDialog.Builder(getActivity(), R.style.SimpleAlertStyle).create();
    alertDialog.setTitle(title);//w  ww .j  a v a  2s . co  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.aikidonord.Intervenant.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_intervenant);

    View rlLoading = findViewById(R.id.loadingPanel);
    View listView = findViewById(R.id.list);

    ActionBar actionBar = this.getSupportActionBar();

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(getResources().getString(R.string.actionbar_titre_intervenant));

    if (VerifConnexion.isOnline(this)) {

        rlLoading.setVisibility(View.VISIBLE);
        listView.setVisibility(View.GONE);

        new QueryForAnimateurTask().execute(this, this.getApplicationContext());
    } else {//from  ww  w . ja va2  s .  c  o m

        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        Intervenant.this.finish();
                    }
                });
        alertDialog.show();
    }

}

From source file:com.yeldi.yeldibazaar.FDroid.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case UPDATE_REPO:
        updateRepos();//from  ww w.  j  a va 2s . com
        return true;

    case MANAGE_REPO:
        Intent i = new Intent(this, ManageRepo.class);
        startActivityForResult(i, REQUEST_MANAGEREPOS);
        return true;

    case PREFERENCES:
        Intent prefs = new Intent(getBaseContext(), PreferencesActivity.class);
        startActivityForResult(prefs, REQUEST_PREFS);
        return true;

    case SEARCH:
        onSearchRequested();
        return true;

    case ABOUT:
        LayoutInflater li = LayoutInflater.from(this);
        View view = li.inflate(R.layout.about, null);

        // Fill in the version...
        TextView tv = (TextView) view.findViewById(R.id.version);
        PackageManager pm = getPackageManager();
        try {
            PackageInfo pi = pm.getPackageInfo(getApplicationContext().getPackageName(), 0);
            tv.setText(pi.versionName);
        } catch (Exception e) {
        }

        Builder p = new AlertDialog.Builder(this).setView(view);
        final AlertDialog alrt = p.create();
        alrt.setIcon(R.drawable.icon);
        alrt.setTitle(getString(R.string.about_title));
        alrt.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.about_website),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Uri uri = Uri.parse("https://f-droid.org");
                        startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    }
                });
        alrt.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
        alrt.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}