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

@Deprecated
public void setButton(CharSequence text, final OnClickListener listener) 

Source Link

Document

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

Usage

From source file:sssemil.com.hostsaway.ui.RedirectionListFragment.java

/**
 * Edit entry based on selection in context menu
 *
 * @param info//from w  w w .j  a v  a 2 s. c  om
 */
private void menuEditEntry(AdapterContextMenuInfo info) {
    mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button
    int position = info.position;
    View v = info.targetView;

    TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position);
    TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position);

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setCancelable(true);
    builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title));

    // build view from layout
    LayoutInflater factory = LayoutInflater.from(mActivity);
    final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null);
    final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname);
    final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip);

    // set text from list
    hostnameEditText.setText(hostnameTextView.getText());
    ipEditText.setText(ipTextView.getText());

    // move cursor to end of EditText
    Editable hostnameEditContent = hostnameEditText.getText();
    hostnameEditText.setSelection(hostnameEditContent.length());
    Editable ipEditContent = ipEditText.getText();
    ipEditText.setSelection(ipEditContent.length());

    builder.setView(dialogView);

    builder.setPositiveButton(getResources().getString(R.string.button_save),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    String hostname = hostnameEditText.getText().toString();
                    String ip = ipEditText.getText().toString();

                    if (RegexUtils.isValidHostname(hostname)) {
                        if (RegexUtils.isValidIP(ip)) {
                            ProviderHelper.updateRedirectionListItemHostnameAndIp(mActivity, mCurrentRowId,
                                    hostname, ip);
                        } else {
                            AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                            alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                            alertDialog.setTitle(R.string.no_ip_title);
                            alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_ip));
                            alertDialog.setButton(getString(R.string.button_close),
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dlg, int sum) {
                                            dlg.dismiss();
                                        }
                                    });
                            alertDialog.show();
                        }
                    } else {
                        AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
                        alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                        alertDialog.setTitle(R.string.no_hostname_title);
                        alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_hostname));
                        alertDialog.setButton(getString(R.string.button_close),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dlg, int sum) {
                                        dlg.dismiss();
                                    }
                                });
                        alertDialog.show();
                    }
                }
            });
    builder.setNegativeButton(getResources().getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.loon.framework.android.game.LGameActivity.java

/**
 * ??Alter//from   ww w . ja v a 2 s. c  o  m
 * 
 * @param message
 */
public void showAndroidAlert(final String title, final String message) {
    Runnable showAlert = new Runnable() {
        public void run() {
            final AlertDialog alert = new AlertDialog.Builder(LGameActivity.this).create();
            alert.setTitle(title);
            alert.setMessage(message);
            alert.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    alert.dismiss();
                }
            });
            alert.show();
        }
    };
    runOnUiThread(showAlert);
}

From source file:org.umit.icm.mobile.gui.ControlActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.controlactivity);
    WebsiteSuggestButton = (Button) this.findViewById(R.id.suggestWebsite);
    ServiceSuggestButton = (Button) this.findViewById(R.id.suggestService);
    scanButton = (Button) this.findViewById(R.id.scanButton);
    //        filterButton = (Button) this.findViewById(R.id.filterButton);
    //       servicesFilterButton = (Button) this.findViewById(R.id.serviceFilterButton);
    mapSelectionButton = (Button) this.findViewById(R.id.mapSelectionButton);
    enableTwitterButton = (Button) this.findViewById(R.id.enableTwitterButton);
    bugReportButton = (Button) this.findViewById(R.id.bugReportButton);
    aboutButton = (Button) this.findViewById(R.id.aboutButton);
    scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off));
    try {//from w  w  w  .  j a v  a  2s.c o m
        if (Globals.runtimeParameters.getTwitter().equals("Off")) {
            enableTwitterButton.setText(getString(R.string.enable_twitter_button));
        } else {
            enableTwitterButton.setText(getString(R.string.disable_twitter_button));
        }
    } catch (RuntimeException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("org.umit.icm.mobile.CONTROL_ACTIVITY")) {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on));
            }
        }
    };

    registerReceiver(receiver, new IntentFilter("org.umit.icm.mobile.CONTROL_ACTIVITY"));

    WebsiteSuggestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            WebsiteSuggestionDialog websiteSuggestionDialog = new WebsiteSuggestionDialog(ControlActivity.this,
                    "", new OnReadyListener());
            websiteSuggestionDialog.show();
        }

    });

    ServiceSuggestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ServiceSuggestionDialog suggestionDialog = new ServiceSuggestionDialog(ControlActivity.this, "",
                    new OnReadyListener());
            suggestionDialog.show();
        }

    });

    enableTwitterButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                if (Globals.runtimeParameters.getTwitter().equals("Off")) {
                    progressDialog = ProgressDialog.show(ControlActivity.this, getString(R.string.loading),
                            getString(R.string.retrieving_website), true, false);
                    new LaunchBrowser().execute();
                    TwitterDialog twitterDialog = new TwitterDialog(ControlActivity.this, "");
                    twitterDialog.show();
                    enableTwitterButton.setText(getString(R.string.disable_twitter_button));
                } else {
                    Globals.runtimeParameters.setTwitter("Off");
                    enableTwitterButton.setText(getString(R.string.enable_twitter_button));
                }
            } catch (RuntimeException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    });

    mapSelectionButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            MapSelectionDialog MapSelectionDialog = new MapSelectionDialog(ControlActivity.this, "");
            MapSelectionDialog.show();
        }

    });

    /*      filterButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) {                                           
        Intent intent = new Intent(ControlActivity.this, WebsiteFilterActivity.class);                
       startActivity(intent); 
     }
            
           }  );
                  
          servicesFilterButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) {                                           
        Intent intent = new Intent(ControlActivity.this, ServiceFilterActivity.class);                
       startActivity(intent); 
     }
            
           }  );*/

    bugReportButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(ControlActivity.this, BugReportActivity.class);
            startActivity(intent);
        }

    });

    aboutButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            String msg = getString(R.string.about_text) + "\n" + getString(R.string.link_to_open_monitor) + "\n"
                    + getString(R.string.link_to_umit) + "\n" + getString(R.string.icons_by);

            final SpannableString spannableString = new SpannableString(msg);
            Linkify.addLinks(spannableString, Linkify.ALL);

            AlertDialog alertDialog = new AlertDialog.Builder(ControlActivity.this).create();
            alertDialog.setTitle(getString(R.string.about_button));
            alertDialog.setMessage(spannableString);
            alertDialog.setIcon(R.drawable.umit_128);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();

                }
            });
            alertDialog.show();

        }

    });

    scanButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (Globals.scanStatus.equalsIgnoreCase(getString(R.string.scan_on))) {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on));
                Globals.scanStatus = getString(R.string.scan_off);
                stopService(new Intent(ControlActivity.this, ConnectivityService.class));
            }

            else {
                scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off));
                Globals.scanStatus = getString(R.string.scan_on);
                startService(new Intent(ControlActivity.this, ConnectivityService.class));
            }

            try {
                Globals.runtimeParameters.setScanStatus(Globals.scanStatus);
            } catch (RuntimeException e) {
                e.printStackTrace();
            }

            Context context = getApplicationContext();
            CharSequence text = getString(R.string.toast_scan_change) + " " + Globals.scanStatus;
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }

    });

}

From source file:fm.smart.r1.activity.CreateItemActivity.java

public void onWindowFocusChanged(boolean bool) {
    super.onWindowFocusChanged(bool);
    Log.d("DEBUG", "onWindowFocusChanged");
    if (CreateItemActivity.create_item_result != null) {
        synchronized (CreateItemActivity.create_item_result) {
            final AlertDialog dialog = new AlertDialog.Builder(this).create();
            final boolean success = CreateItemActivity.create_item_result.success();
            final String item_id = CreateItemActivity.create_item_result.http_response;
            dialog.setTitle(CreateItemActivity.create_item_result.getTitle());
            dialog.setMessage(CreateItemActivity.create_item_result.getMessage());
            CreateItemActivity.create_item_result = null;
            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // TODO avoid moving to item view if previous thread was
                    // interrupted? create_item.isInterrupted() but need
                    // user to be aware if we
                    // have created example already - progress dialog is set
                    // cancelable, so back button will work? maybe should
                    // avoid encouraging cancel
                    // on POST operations ... not sure what to do if no
                    // response from server - guess we will time out
                    // eventually ...
                    if (success) {
                        // want to go to individual item screen now ...
                        ItemListActivity.loadItem(CreateItemActivity.this, item_id);
                    }//from   ww w.j  a v a2 s . c o m
                }
            });
            dialog.show();

        }
    }
}

From source file:org.uclab.mm.sl.uiux.uiuxanalyticsdemo.MainActivity.java

public void userFeedback() {
    AlertDialog userfeedback = new AlertDialog.Builder(this).create();

    // Setting Dialog Title
    userfeedback.setTitle("Feedback");

    // Setting Icon to Dialog
    userfeedback.setIcon(R.drawable.ic_feedback_black_18dp);

    LayoutInflater inflater = this.getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    userfeedback.setView(inflater.inflate(R.layout.feedback, null));

    // Setting OK Button
    userfeedback.setButton("Send", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog
            // closed
            Toast.makeText(getApplicationContext(), "Your Feedback sent Successfully", Toast.LENGTH_SHORT)
                    .show();// w  ww  . j  av a  2  s  .  co  m
        }
    });

    // Showing Alert Message
    userfeedback.show();
}

From source file:fm.smart.r1.activity.CreateSoundActivity.java

public void onWindowFocusChanged(boolean bool) {
    super.onWindowFocusChanged(bool);
    Log.d("DEBUG", "onWindowFocusChanged");
    if (CreateSoundActivity.create_sound_result != null) {
        synchronized (CreateSoundActivity.create_sound_result) {
            final AlertDialog dialog = new AlertDialog.Builder(this).create();
            final boolean success = CreateSoundActivity.create_sound_result.success();
            dialog.setTitle(CreateSoundActivity.create_sound_result.getTitle());
            dialog.setMessage(CreateSoundActivity.create_sound_result.getMessage());
            CreateSoundActivity.create_sound_result = null;
            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // TODO avoid moving to item list if previous thread was
                    // interrupted? create_sound.isInterrupted() but need
                    // user to be aware if we
                    // have created sound already - progress dialog is set
                    // cancelable, so back button will work? maybe should
                    // avoid encouraging cancel
                    // on POST operations ... not sure what to do if no
                    // response from server - guess we will time out
                    // eventually ...
                    // if (success) {
                    // want to go back to individual item screen now ...
                    ItemListActivity.loadItem(CreateSoundActivity.this, item_id);
                    // }
                    // TODO might want to go to different screens depending
                    // on type of error, e.g. permission issue versus
                    // network
                    // error
                }/*from  w  w w . ja v a  2 s  . c  o  m*/
            });
            dialog.show();

        }
    }
}

From source file:org.odk.collect.android.activities.FormChooserList.java

/**
 * Creates a dialog with the given message. Will exit the activity when the user preses "ok" if
 * shouldExit is set to true./*from   w w  w .j a v a  2s  .com*/
 */
private void createErrorDialog(String errorMsg, final boolean shouldExit) {

    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setIcon(android.R.drawable.ic_dialog_info);
    alertDialog.setMessage(errorMsg);
    DialogInterface.OnClickListener errorListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int i) {
            switch (i) {
            case DialogInterface.BUTTON_POSITIVE:
                if (shouldExit) {
                    finish();
                }
                break;
            }
        }
    };
    alertDialog.setCancelable(false);
    alertDialog.setButton(getString(R.string.ok), errorListener);
    alertDialog.show();
}

From source file:com.glm.trainer.NewMainActivity.java

@Override
public void onBackPressed() {
    AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(this.getString(R.string.titleendapp));
    alertDialog.setMessage(this.getString(R.string.messageendapp));
    alertDialog.setButton(this.getString(R.string.yes), new android.content.DialogInterface.OnClickListener() {

        @Override//  w ww.  ja  va 2  s  .co m
        public void onClick(DialogInterface arg0, int arg1) {
            if (mConnection != null && mConnection.mIService != null) {
                try {
                    mConnection.mIService.stopGPSFix();
                    mConnection.mIService.shutDown();
                    mConnection.destroy();
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    //Log.e(this.getClass().getCanonicalName(),e.getMessage());
                }
            }
            finish();
        }
    });

    alertDialog.setButton2(this.getString(R.string.no), new android.content.DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {

        }

    });
    alertDialog.show();
}

From source file:com.glm.trainer.NewMainActivity.java

/**
 * Visualizza una alert per il GPS non abilitato
 *
 * @author Gianluca Masci aka (GLM)//from www .j av  a  2s.  com
 * */
public void ShowAlertNoGPS() {
    try {
        AlertDialog alertDialog;
        alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle(this.getString(R.string.titlegps));
        alertDialog.setMessage(this.getString(R.string.messagegpsnoenabled));
        alertDialog.setButton(this.getString(R.string.yes),
                new android.content.DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivity(myIntent);
                    }
                });

        alertDialog.setButton2(this.getString(R.string.no),
                new android.content.DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {

                    }

                });
        alertDialog.show();
    } catch (Exception e) {
        Toast.makeText(this, "ERROR DIALOG:" + e.getMessage(), Toast.LENGTH_SHORT).show();
        Log.e("MEEERR: ", e.getMessage());
    }
}

From source file:org.odk.collect.android.activities.InstanceChooserList.java

private void createErrorDialog(String errorMsg, final boolean shouldExit) {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setIcon(android.R.drawable.ic_dialog_info);
    alertDialog.setMessage(errorMsg);/*  w w w  .j a  v  a2 s.  co  m*/
    DialogInterface.OnClickListener errorListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int i) {
            switch (i) {
            case DialogInterface.BUTTON_POSITIVE:
                if (shouldExit) {
                    finish();
                }
                break;
            }
        }
    };
    alertDialog.setCancelable(false);
    alertDialog.setButton(getString(R.string.ok), errorListener);
    alertDialog.show();
}