Android DialogInterface - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android DialogInterface class.

This code example shows how to use the following methods:dismiss
        return dialog;
    } 
 
    @Override 
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
        switch (which) {
        case BUTTON_POSITIVE:
            onResult(RESULT_OK);
            break; 
        case BUTTON_NEGATIVE:
            onResult(RESULT_CANCELED);
            break; 
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:dismiss
        return dialog;
    } 
 
    @Override 
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
    } 
} 
8
CodeRank
This code example shows how to use the following methods:cancel
                public void onClick(DialogInterface dialog, int index) { 
                    if (index >= 0 && index < mAccounts.length) { 
                        mAccount = mAccounts[index]; 
                        startAuthentication(); 
                    } 
                    dialog.cancel(); 
                } 
            }; 
 
    public IITC_DeviceAccountLogin(IITC_Mobile activity, WebView webView,
                                   WebViewClient webViewClient) {
        mActivity = activity;
        mWebView = webView;
        mAccountManager = AccountManager.get(activity);
        mAccountAdapter = new AccountAdapter();
 
        // dialog that serves as a progress bar overlay 
        mProgressbar = new AlertDialog.Builder(mActivity)
                .setCancelable(false)
                .setView(mActivity.getLayoutInflater().inflate(R.layout.dialog_progressbar, null))
7
CodeRank
This code example shows how to use the following methods:dismiss
                    View decor = win.getDecorView();
                    if (decor != null) {
                        KeyEvent.DispatcherState ds = decor.getKeyDispatcherState();
                        if (ds != null && ds.isTracking(event)) {
                            mMenu.close(true);
                            dialog.dismiss();
                            return true; 
                        } 
                    } 
                } 
            } 
        } 
 
        // Menu shortcut matching 
        return mMenu.performShortcut(keyCode, event, 0);
 
    } 
 
    public void setPresenterCallback(MenuPresenter.Callback cb) { 
        mPresenterCallback = cb; 
7
CodeRank
This code example shows how to use the following methods:dismiss
            builder.setSingleChoiceItems(items, -1,
                    new DialogInterface.OnClickListener(){
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                        case OPEN_DIRECTORY:
                            dialog.dismiss();
                            mPath = path;
                            mFocusFile = null;
                            updateList(); 
                            break; 
                        case RUN_TESTS:
                            dialog.dismiss();
                            processDirectory(path, false);
                            break; 
                    } 
                } 
            }); 
            builder.create().show();
        } else { 
            processFile(path, false);
7
CodeRank
This code example shows how to use the following methods:cancel
                .setPositiveButton( 
                        context.getResources().getString(
                                R.string.ok),
                        new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    } 
                }); 
        return  builder.create();   
    } 
     
    /** 
     * @return  HTML displaying the changes since the previous 
     *          installed version of your app (what's new) 
     */ 
    public String getLog() {
        return  this.getLog(false);
    } 
 
    /** 
6
CodeRank
This code example shows how to use the following methods:dismiss
                }); 
        builder.setNegativeButton(android.R.string.cancel,
                new DialogInterface.OnClickListener() {
                    @Override 
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    } 
                }); 
        return builder.create();
    } 
} 
7
CodeRank
This code example shows how to use the following methods:cancel
     */ 
    @Override 
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case DialogInterface.BUTTON_NEGATIVE:
                dialog.cancel();
                break; 
            case DialogInterface.BUTTON_POSITIVE:
                final long accountId = getArguments().getLong("accountId");
                final String text = mQuickResponseEditText.getText().toString();
                final Context context = getActivity();
                if (mQuickResponse == null) {
                    mQuickResponse = new QuickResponse(accountId, text);
                } 
 
                // Insert the new QuickResponse into the database. Content watchers used to 
                // update the ListView of QuickResponses upon insertion. 
                EmailAsyncTask.runAsyncParallel(new Runnable() {
                    @Override 
                    public void run() { 
6
CodeRank
This code example shows how to use the following methods:dismiss
		this.setTitle( title );
		this.setMessage( message );
		this.setCancelable( false );
		this.setButton( "Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            	dialog.dismiss();
            } 
        });			 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:cancel, dismiss
This code example shows how to use the following methods:dismiss
        builder.setCancelable(false);
        builder.setPositiveButton(context.getString(android.R.string.ok), new OnClickListener() {
 
            @Override 
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            } 
        }); 
 
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setIcon(iconId);
 
        return builder;
    } 
 
    public static AlertDialog.Builder newMessageDialog(final Context context, int titleId,
            int messageId, int iconId) {
        return newMessageDialog(context, context.getString(titleId), context.getString(messageId),
                iconId);
7
CodeRank
This code example shows how to use the following methods:cancel
    			        finish();
    		        } 
    			}) 
    		.setNegativeButton(R.string.cancel_dialog, new AlertDialog.OnClickListener() {
    			public void onClick(DialogInterface dialog, int which) {
    			        dialog.cancel();
    			} 
    			}) 
    			.create(); 
    		return alertDialog;
    		default: 
    			//@SuppressWarnings("deprecation") 
    			return super.onCreateDialog(id);
    	} 
    } 
     
    public void qdWay(View v) {
    	Log.d(TAG, "Quick&Dirty Way invoked");
    	Dialog dlg = onCreateDialog(DLG_UNSAVED);
    	dlg.show();
6
CodeRank
This code example shows how to use the following methods:dismiss
		this.setTitle( title );
		this.setMessage( message );
		this.setCancelable( false );
		this.setButton( "Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            	dialog.dismiss();
            	activity.finish();
            } 
        });			 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:cancel
                .setTitle(getString(R.string.imei_not_sane_title))
                .setMessage(getString(R.string.imei_not_sane_message))
                .setPositiveButton(getString(R.string.imei_not_sane_ok),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                                finish();
                            } 
                        }) 
                .setCancelable(false) 
                .create().show(); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:dismiss
		this.setTitle( "About dSploit v" + System.getAppVersionName() );
		this.setView( view );
 
		this.setButton( "Ok", new DialogInterface.OnClickListener() {
            public void onClick( DialogInterface dialog, int id ) {
            	dialog.dismiss();
            } 
        });			 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:cancel
		Dialog aboutDialog = new AlertDialog.Builder(getActivity()).setView(view)
				.setTitle(getString(R.string.dialog_about_title))
				.setNeutralButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
					@Override 
					public void onClick(DialogInterface dialog, int id) {
						dialog.cancel();
					} 
				}).create(); 
		aboutDialog.setCanceledOnTouchOutside(true);
 
		return aboutDialog;
	} 
} 
6
CodeRank
This code example shows how to use the following methods:dismiss
		}); 
		return this;
	} 
 
	protected void onCancel(DialogInterface dialog) {
		dialog.dismiss();
		onCancelListener.onCancel(this);
	} 
 
	/** 
	 * @return Title for the negative button. 
	 */ 
	protected String getNegativeTitle() {
		return activity.getString(android.R.string.no);
	} 
 
	/** 
	 * Sets listener for dialog to be declined by pushing on negative button. 
	 *  
	 * @param listener 
7
CodeRank
This code example shows how to use the following methods:dismiss
This code example shows how to use the following methods:cancel
                    .setTitle(R.string.modem_error)
                    .setMessage(R.string.device_rebooted_modem_error) 
                    .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        @Override 
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        } 
                    }) 
                    .setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override 
                        public void onCancel(DialogInterface dialog) {
                            finish();
                        } 
                    }) 
                    .create(); 
        } 
 
        return super.onCreateDialog(id, args);
    } 
 
6
CodeRank
This code example shows how to use the following methods:dismiss
 
    public void onClick(DialogInterface dialog, int which) {
        if (mCallback != null) {
            mNumberPicker.clearFocus();
            mCallback.onNumberSet(mNumberPicker.getCurrent());
            dialog.dismiss();
        } 
    } 
 
    @Override 
    public Bundle onSaveInstanceState() {
        Bundle state = super.onSaveInstanceState();
        state.putInt(NUMBER, mNumberPicker.getCurrent());
        return state;
    } 
 
    @Override 
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        int number = savedInstanceState.getInt(NUMBER);
7
CodeRank
This code example shows how to use the following methods:cancel
         
        builder.setMessage("Esto es un mensaje de alerta.")
        	   .setTitle("Información")
               .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                	   dialog.cancel();
                   } 
               }); 
 
        return builder.create();
    } 
} 
6
CodeRank
This code example shows how to use the following methods:dismiss
 
    public void onClick(DialogInterface dialog, int which) {
        if (mCallback != null) {
            mNumberPicker.clearFocus();
            mCallback.onNumberSet(mDialogId, mNumberPicker.getValue());
            dialog.dismiss();
        } 
    } 
 
    @Override 
    public Bundle onSaveInstanceState() {
        Bundle state = super.onSaveInstanceState();
        state.putInt(NUMBER, mNumberPicker.getValue());
        return state;
    } 
 
    @Override 
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        int number = savedInstanceState.getInt(NUMBER);
7
CodeRank
This code example shows how to use the following methods:cancel
                   } 
               }) 
               .setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                	   	Log.i("Dialogos", "Confirmacion Cancelada.");
       					dialog.cancel();
                   } 
               }); 
 
        return builder.create();
    } 
} 
6
CodeRank
This code example shows how to use the following methods:dismiss
		builder.setNeutralButton(android.R.string.ok,
				new DialogInterface.OnClickListener() {
 
					@Override 
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					} 
				}) 
				.setTitle(R.string.download_error_request_error)
				.setMessage( 
						context.getString(R.string.download_request_error_dialog_message_prefix)
								+ errorMessage);
		builder.create().show();
	} 
} 
7
CodeRank
This code example shows how to use the following methods:cancel
            }) 
            .setNegativeButton("No",new DialogInterface.OnClickListener() {
 
                public void onClick(DialogInterface dialog, int which) {
                	 
                	dialog.cancel();
                        
                } 
            }) 
            .show(); 
 
            return ; 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:dismiss
            AlertDialog ad = new AlertDialog.Builder(this).create();  
            ad.setCancelable(false); // This blocks the 'BACK' button  
            ad.setMessage("Fatal error: can't open camera!");  
            ad.setButton("OK", new DialogInterface.OnClickListener() {  
                public void onClick(DialogInterface dialog, int which) {  
                    dialog.dismiss();                      
                    finish();
                }   
            });   
            ad.show();
        } 
    } 
 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "onCreate");
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mView = new CartoonifierView(this);
7
CodeRank
This code example shows how to use the following methods:cancel
 
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose Geo App");
            builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    dialog.cancel();
 
                    String intentUrl = "";
                    if (items[item].compareTo("Maps") == 0) {
                        intentUrl = "geo:" + url;
                    } else if (items[item].compareTo("Navigation") == 0) {
                        intentUrl = "google.navigation:" + url;
                    } else if (items[item].compareTo("Street View") == 0) {
                        intentUrl = "google.streetview:cbll=" + url;
                    } 
 
                    try { 
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentUrl));
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
6
CodeRank
This code example shows how to use the following methods:dismiss
				.setMessage("Clicked!")
				.setTitle("onClickTest")
				.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					@Override 
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					} 
				}) 
				.create().show();
			} 
		}); 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:cancel
				launchAccountOptions();  
			} 
		}) 
		.setNegativeButton("No", new DialogInterface.OnClickListener() {
			public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
				dialog.cancel();
				System.exit(0);
			} 
		}); 
 
 
		final AlertDialog alert = builder.create();
		alert.show();
	} 
 
	private void launchAccountOptions(){ 
		final Intent intent = new Intent(Settings.ACTION_SYNC_SETTINGS);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivityForResult(intent, 1);
	} 
6
CodeRank
This code example shows how to use the following methods:dismiss

Related Android DialogInterface Questions & Answers:

Other Android DialogInterface Examples

26:	private final class CancelOnClickListener implements
27:	    DialogInterface.OnClickListener {
28:	  public void onClick(DialogInterface dialog, int which) {
29:	    Toast.makeText(getApplicationContext(), "Cancle selected, activity continues",
30:	        Toast.LENGTH_LONG).show();
-
34:	private final class OkOnClickListener implements
35:	    DialogInterface.OnClickListener {
36:	  public void onClick(DialogInterface dialog, int which) {
37:	    AlertExampleActivity.this.finish();
38:	  }

Read More

11:					// Setting Positive "Yes" Button
12:					alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
13:						public void onClick(DialogInterface dialog, int which) {
14:						// User pressed YES button. Write Logic Here
15:						Toast.makeText(getApplicationContext(), "You clicked on YES",
-
20:					// Setting Negative "NO" Button
21:					alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
22:						public void onClick(DialogInterface dialog, int which) {
23:						// User pressed No button. Write Logic Here
24:						Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
-
28:					// Setting Netural "Cancel" Button
29:					alertDialog.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
30:						public void onClick(DialogInterface dialog, int which) {
31:						// User pressed Cancel button. Write Logic Here
32:						Toast.makeText(getApplicationContext(), "You clicked on Cancel",

Read More

11:			// Setting Positive "Yes" Button
12:			alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
13:				public void onClick(DialogInterface dialog,int which) {
14:	
15:				// Write your code here to invoke YES event
-
20:			// Setting Negative "NO" Button
21:			alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
22:				public void onClick(DialogInterface dialog,	int which) {
23:				// Write your code here to invoke NO event
24:				Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();

Read More

12:			// Setting OK Button
13:			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
14:					public void onClick(DialogInterface dialog, int which) {
15:					// Write your code here to execute after dialog closed
16:					Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();

Read More

See Code Examples for Android DialogInterface Methods: