本文整理汇总了Java中android.content.DialogInterface.OnClickListener方法的典型用法代码示例。如果您正苦于以下问题:Java DialogInterface.OnClickListener方法的具体用法?Java DialogInterface.OnClickListener怎么用?Java DialogInterface.OnClickListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.DialogInterface
的用法示例。
在下文中一共展示了DialogInterface.OnClickListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOptionsItemSelected
import android.content.DialogInterface; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// User clicked on a menu option in the app bar overflow menu
switch (item.getItemId()) {
// Respond to a click on the "Save" menu option
case R.id.action_save:
// insert the pet to database
savePet();
// close the windows with the forms
finish();
return true;
// Respond to a click on the "Delete" menu option
case R.id.action_delete:
// Do nothing for now
return true;
// Respond to a click on the "Up" arrow button in the app bar
case android.R.id.home:
// Navigate back to parent activity (CatalogActivity)
// if no changes, continue back to parent activity
if (!mPetHasChanged) {
NavUtils.navigateUpFromSameTask(EditorActivity.this);
return true;
}
// if there are unsaved changes
DialogInterface.OnClickListener discardButtonClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// User clicked "Discard Button"
NavUtils.navigateUpFromSameTask(EditorActivity.this);
}
};
// Show Dialog
showUnsavedChangesDialog(discardButtonClickListener);
return true;
}
return super.onOptionsItemSelected(item);
}
示例2: popup_show
import android.content.DialogInterface; //导入方法依赖的package包/类
/**CUSTOMIZEABLE pop up input text for positive button (right button) and negative button (left button)*/
public void popup_show(String popup_title, String popup_hint, DialogInterface.OnClickListener positiveOCL,DialogInterface.OnClickListener negativeOCL, String positiveText, String negativeText)
{
//build popup dialogue
popUpWindow = new AlertDialog.Builder(context);
popUpWindow.setTitle(popup_title);
//set up the input field
popup_inputText = new EditText(context);
popup_inputText.setInputType(InputType.TYPE_CLASS_TEXT);
popup_inputText.setHint(popup_hint); //set hint on what value the user should enter
popUpWindow.setView(popup_inputText);
//set up positive button
popUpWindow.setPositiveButton(positiveText, positiveOCL);
//set up negative button
popUpWindow.setNegativeButton(negativeText, negativeOCL);
popUpWindow.show();
}
示例3: getConfirmDialog
import android.content.DialogInterface; //导入方法依赖的package包/类
/**
* 获取一个验证对话框
*/
public static AlertDialog.Builder getConfirmDialog(
Context context,
String title,
String message,
String positiveText,
String negativeText,
boolean cancelable,
DialogInterface.OnClickListener positiveListener,
DialogInterface.OnClickListener negativeListener) {
return getDialog(context)
.setCancelable(cancelable)
.setTitle(title)
.setMessage(message)
.setPositiveButton(positiveText, positiveListener)
.setNegativeButton(negativeText, negativeListener);
}
示例4: getInputDialog
import android.content.DialogInterface; //导入方法依赖的package包/类
/**
* 获取一个输入对话框
*/
public static AlertDialog.Builder getInputDialog(
Context context,
String title,
AppCompatEditText editText,
String positiveText,
String negativeText,
boolean cancelable,
DialogInterface.OnClickListener positiveListener,
DialogInterface.OnClickListener negativeListener) {
return getDialog(context)
.setCancelable(cancelable)
.setTitle(title)
.setView(editText)
.setPositiveButton(positiveText, positiveListener)
.setNegativeButton(negativeText, negativeListener);
}
示例5: onRequestPermissionsResult
import android.content.DialogInterface; //导入方法依赖的package包/类
/**
* Callback for the result from requesting permissions. This method
* is invoked for every call on {@link #requestPermissions(String[], int)}.
* <p>
* <strong>Note:</strong> It is possible that the permissions request interaction
* with the user is interrupted. In this case you will receive empty permissions
* and results arrays which should be treated as a cancellation.
* </p>
*
* @param requestCode The request code passed in {@link #requestPermissions(String[], int)}.
* @param permissions The requested permissions. Never null.
* @param grantResults The grant results for the corresponding permissions
* which is either {@link PackageManager#PERMISSION_GRANTED}
* or {@link PackageManager#PERMISSION_DENIED}. Never null.
* @see #requestPermissions(String[], int)
*/
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode != RC_HANDLE_CAMERA_PERM) {
Log.d(TAG, "Got unexpected permission result: " + requestCode);
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
return;
}
if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Camera permission granted - initialize the camera source");
// we have permission, so create the camerasource
//boolean autoFocus = getIntent().getBooleanExtra(AutoFocus,false);
//boolean useFlash = getIntent().getBooleanExtra(UseFlash, false);
createCameraSource(true);
return;
}
Log.e(TAG, "Permission not granted: results len = " + grantResults.length +
" Result code = " + (grantResults.length > 0 ? grantResults[0] : "(empty)"));
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("QR Scanner")
.setMessage("This application cannot run because it does not have the camera permission. The application will now exit.")
.setPositiveButton("OK", listener)
.show();
}
示例6: showAchievement
import android.content.DialogInterface; //导入方法依赖的package包/类
/**
* Shows an already unlocked achievement listed in the achievement activity.
*
* @param achievement The unlocked achievement to show.
* @param context The application context.
* @return The achievement.
*/
public static AlertDialog showAchievement(Achievement achievement, Context context,
DialogInterface.OnClickListener onSubmitListener) {
return showAchievement(achievement, context, onSubmitListener, achievement.getHeading(),
achievement.getShareText(),
context.getResources().getString(R.string.achievement_requirements_heading_unlocked),
achievement.getRequirements());
}
示例7: showDefaultAppSettingsDialog
import android.content.DialogInterface; //导入方法依赖的package包/类
private static void showDefaultAppSettingsDialog(@NonNull final BasePermissionInvoker invoker,
final int requestCode) {
final Context context = invoker.getContext();
final DialogInterface.OnClickListener settingListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
invoker.startActivityForResult(
PermissionDialogs.appSettingsIntent(context), requestCode);
}
};
showAppSettingsDialog(context, R.string.hey_permission_permission_denied,
settingListener, null);
}
示例8: createAccountPicker
import android.content.DialogInterface; //导入方法依赖的package包/类
/**
* Creates an account picker dialog showing the given accounts in a list and selecting
* the selected account by default. The list of accounts must not be null/empty.
*
* Package-private for testing.
*
* @param accounts list of accounts on the device.
* @param selectedAccount currently selected account
* @param positiveButtonClickListener listener that gets called when positive button is
* clicked
*/
@UsedForTesting
AlertDialog createAccountPicker(final String[] accounts,
final String selectedAccount,
final DialogInterface.OnClickListener positiveButtonClickListener) {
if (accounts == null || accounts.length == 0) {
throw new IllegalArgumentException("List of accounts must not be empty");
}
// See if the currently selected account is in the list.
// If it is, the entry is selected, and a sign-out button is provided.
// If it isn't, select the 0th account by default which will get picked up
// if the user presses OK.
int index = 0;
boolean isSignedIn = false;
for (int i = 0; i < accounts.length; i++) {
if (TextUtils.equals(accounts[i], selectedAccount)) {
index = i;
isSignedIn = true;
break;
}
}
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.account_select_title)
.setSingleChoiceItems(accounts, index, null)
.setPositiveButton(R.string.account_select_ok, positiveButtonClickListener)
.setNegativeButton(R.string.account_select_cancel, null);
if (isSignedIn) {
builder.setNeutralButton(R.string.account_select_sign_out, positiveButtonClickListener);
}
return builder.create();
}
示例9: showAlert
import android.content.DialogInterface; //导入方法依赖的package包/类
public static AlertDialog showAlert(final Context context, final int msg, final int title, final int yes, final int no, final DialogInterface.OnClickListener lOk,
final DialogInterface.OnClickListener lCancel) {
if (context instanceof Activity && ((Activity) context).isFinishing()) {
return null;
}
final Builder builder = new AlertDialog.Builder(context);
builder.setIcon(R.drawable.ic_dialog_alert);
builder.setTitle(title);
builder.setMessage(msg);
builder.setPositiveButton(yes, lOk);
builder.setNegativeButton(no, lCancel);
// builder.setCancelable(false);
final AlertDialog alert = builder.create();
alert.show();
return alert;
}
示例10: showDialogDualActions
import android.content.DialogInterface; //导入方法依赖的package包/类
public static void showDialogDualActions(Context context, String title, String message, String positive, String negative, DialogInterface.OnClickListener positiveCallback, DialogInterface.OnClickListener negativeCallback) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title)
.setMessage(message)
.setPositiveButton(positive, positiveCallback)
.setNegativeButton(negative, negativeCallback);
builder.create().show();
}
示例11: setNegativeButton
import android.content.DialogInterface; //导入方法依赖的package包/类
@Override
public Dialog setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener) {
return (Dialog) super.setNegativeButton(text, listener);
}
示例12: showError
import android.content.DialogInterface; //导入方法依赖的package包/类
@SuppressWarnings({"WeakerAccess", "unused"})
public Dialog showError(Throwable e, DialogInterface.OnClickListener clickListener) {
return showError(e.getMessage(), clickListener);
}
示例13: onActivityResult
import android.content.DialogInterface; //导入方法依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ( resultCode != RESULT_OK )
return;
// Get photo URI if photo chosen from SD Card
if ( requestCode == PICK_FROM_FILE) {
imageCaptureUri = data.getData();
}
// Get an InputStream of the photo
try {
is = view.getContext().getContentResolver().openInputStream(imageCaptureUri);
} catch ( FileNotFoundException e ) {
e.printStackTrace();
}
// Handler for photo upload AlertDialog
dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
// Case to upload photo
case DialogInterface.BUTTON_POSITIVE:
UploadImage( is );
break;
// Case to cancel photo upload
case DialogInterface.BUTTON_NEGATIVE:
break;
}
}
};
// Create EditText field for AlertDialog
input = new EditText(view.getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT);
// Prompt user to upload the photo and allow user to enter a photo description
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
builder.setMessage( "Enter description:" )
.setNegativeButton("Cancel", dialogClickListener)
.setPositiveButton("Upload", dialogClickListener)
.setView(input)
.show();
}
示例14: setSingleChoiceItems
import android.content.DialogInterface; //导入方法依赖的package包/类
@Override
public Builder setSingleChoiceItems(ListAdapter adapter, int checkedItem, final DialogInterface
.OnClickListener listener) {
builder.setSingleChoiceItems(adapter, checkedItem, listener);
return this;
}
示例15: setNegativeButton
import android.content.DialogInterface; //导入方法依赖的package包/类
public ColorPickerDialogBuilder setNegativeButton(CharSequence text, DialogInterface.OnClickListener onClickListener) {
builder.setNegativeButton(text, onClickListener);
return this;
}