AlertDialog setButton - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AlertDialog setButton method.

This code example shows how to use the following methods:setButton, setMessage, setTitle, dismiss, isShowing
            dialog = new AlertDialog.Builder(context)
                    .setPositiveButton(android.R.string.ok, disconnectListener)
                    .setNegativeButton(android.R.string.cancel, null)
                    .create();
        } else { 
            if (dialog.isShowing()) {
                dialog.dismiss();
            } 
            // use disconnectListener for the correct profile(s) 
            CharSequence okText = context.getText(android.R.string.ok);
            dialog.setButton(DialogInterface.BUTTON_POSITIVE,
                    okText, disconnectListener);
        } 
        dialog.setTitle(title);
        dialog.setMessage(message);
        dialog.show();
        return dialog;
    } 
 
    // TODO: wire this up to show connection errors... 
    static void showConnectingError(Context context, String name) {
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton, setTitle, show, setProgressStyle
		noticeDialog = builder.create();
		noticeDialog.show();
	} 
	 
	private static void showDownloadDialog(Context context) {
		  progressDialog   =  new ProgressDialog(context);
		  progressDialog.setTitle("Update software");
		  
		  progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
	progressDialog.setButton("Cancel", new OnClickListener() {
		 
		@Override 
		public void onClick(DialogInterface dialog, int which) {
 
			 dialog.dismiss();
			 interceptFlag = true;
			  
		} 
	}); 
	progressDialog.show();

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton, setTitle, show, setProgressStyle
		noticeDialog = builder.create();
		noticeDialog.show();
	} 
	 
	private static void showDownloadDialog(Context context) {
		  progressDialog   =  new ProgressDialog(context);
		  progressDialog.setTitle("Update software");
		  
		  progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
	progressDialog.setButton("Cancel", new OnClickListener() {
		 
		@Override 
		public void onClick(DialogInterface dialog, int which) {
 
			 dialog.dismiss();
			 interceptFlag = true;
			  
		} 
	}); 
	progressDialog.show();

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton, setCancelable, setCanceledOnTouchOutside, show, setIndeterminate
public class ProgressDialogHelper { 
    private ProgressDialog progressDialog;
 
    public void show(Context context, final ICancelableAsyncTask task, String msg) {
        if (progressDialog == null) {
            progressDialog = new ProgressDialog(context);
            progressDialog.setIndeterminate(true);
            progressDialog.setCancelable(false);
            progressDialog.setCanceledOnTouchOutside(false);
            progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new OnClickListener() {
                @Override 
                public void onClick(DialogInterface dialog, int which) {
                    task.cancel();
                } 
            }); 
        } 
 
        progressDialog.setMessage(msg);
        progressDialog.show();
    } 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton, setMessage, setTitle, show
			 
			*/ 
			 
		} 
		 
		msgDialog.show();
	} 
	 
	private AlertDialog createAlertDialog(String title, String msg, String buttonText){
		AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
		AlertDialog msgDialog = dialogBuilder.create();
		msgDialog.setTitle(title);
		msgDialog.setMessage(msg);
		msgDialog.setButton(buttonText, new DialogInterface.OnClickListener(){
			@Override 
			public void onClick(DialogInterface dialog, int idx){
				return; // Nothing to see here... 
			} 
		}); 
		 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton
        final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);
 
        final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), year, month, day);
 
        if (AndroidVersion.isJBOrAbove()) 
        { 
            picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok),
                    new DialogInterface.OnClickListener()
                    { 
                        @Override 
                        public void onClick(DialogInterface dialog, int which)
                        { 
                            DatePicker dp = picker.getDatePicker();
                            mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
                        } 
                    }); 
            picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel),

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton, setTitle, setCancelable, setCanceledOnTouchOutside, show
	} 
	 
	@Override 
	protected void onPreExecute() { 
		// Build and display the loading spinner 
		progressDialog = new ProgressDialog(context);
		progressDialog.setTitle("Hang Tight!");
		progressDialog.setMessage("Getting an address...");
		progressDialog.setCanceledOnTouchOutside(false);
		progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Stop", new DialogInterface.OnClickListener() {
			 
			@Override 
			public void onClick(DialogInterface dialog, int which) {
				progressDialog.cancel();
				 
				Log.v(TAG, "progress dialog cancelled");
				ReverseGeocodeTask.this.cancel(true);
			} 
		}); 
		progressDialog.setIndeterminate(true);

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton, setTitle, show, setMessage
            ) 
    { 
        // Start thread 
        final DelayThread delayThread = new DelayThread(delayMs, l);
         
        cancelDialog = new ProgressDialog(context);
        cancelDialog.setTitle(title);
        cancelDialog.setMessage(message);
        cancelDialog.setButton(buttonText,
                new DialogInterface.OnClickListener()
                { 
                    public void onClick(DialogInterface dialog, int which)
                    { 
                        // Close the dialog 
                        delayThread.cancel();
                        return; 
                    } 
                }); 
        cancelDialog.show();
        delayThread.start();

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton, setTitle, getWindow, setCancelMessage, setCancelable
    } 
 
    public synchronized void show(final Context context, final String title, final String message, final boolean indeterminate, final Message cancelMessage) {
        if (dialog == null) {
            createProgressDialog(context, title, message, cancelMessage);
            dialog.setIndeterminate(indeterminate);
            dialog.show();
        } 
    } 
 
    public synchronized void show(final Context context, final String title, final String message, final int style, final Message cancelMessage) {
        if (dialog == null) {
            createProgressDialog(context, title, message, cancelMessage);
            dialog.setProgressStyle(style);
            dialog.show();
        } 
    } 
 
    private void createProgressDialog(Context context, String title, String message, Message cancelMessage) {
        if (hideAbsolute) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setButton, setOnCancelListener
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 
		String androidId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
		 
		progress = new ProgressDialog(this);
		alert = new AlertDialog.Builder(this).create();
		AuthHandler handler = new AuthHandler(progress, alert, this, androidId);
		thread = new AuthThread(handler, androidId);
		 
		progress.setOnCancelListener(this);
		progress.setButton(DialogInterface.BUTTON_NEGATIVE, "Annuler", this);
		alert.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", this);
		 
		thread.start();
	} 
 
	public void onClick(DialogInterface dialog, int which) {
		switch(which) {
		case DialogInterface.BUTTON_NEGATIVE:
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related AlertDialog setButton Questions & Answers:

Other AlertDialog setButton Examples

75:	
76:			// Setting OK Button
77:			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
78:				public void onClick(DialogInterface dialog, int which) {
79:				}

Read More

30:	
31:			// Setting OK Button
32:			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
33:				public void onClick(DialogInterface dialog, int which) {
34:				}

Read More

28:	
29:			// Setting OK Button
30:			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
31:				public void onClick(DialogInterface dialog, int which) {
32:				}

Read More

setButton Method Overview
This method was deprecated in API level 3. Use setButton(int, CharSequence, Message) with BUTTON_POSITIVE.
See Code Examples for other Android AlertDialog Methods: