本文整理汇总了Java中android.support.v7.app.AlertDialog.setOnDismissListener方法的典型用法代码示例。如果您正苦于以下问题:Java AlertDialog.setOnDismissListener方法的具体用法?Java AlertDialog.setOnDismissListener怎么用?Java AlertDialog.setOnDismissListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.app.AlertDialog
的用法示例。
在下文中一共展示了AlertDialog.setOnDismissListener方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
@Override
protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
final AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle(R.string.crash_dialog_title)
.setView(R.layout.crash_report_dialog)
.setPositiveButton(R.string.ok, this)
.setNegativeButton(R.string.cancel, this)
.create();
dialog.setCanceledOnTouchOutside(false);
dialog.setOnDismissListener(this);
dialog.show();
comment = (EditText) dialog.findViewById(android.R.id.input);
if (savedInstanceState != null) {
comment.setText(savedInstanceState.getString(STATE_COMMENT));
}
}
示例2: showDisclaimerForFirstTime
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
private void showDisclaimerForFirstTime() {
final SharedPreferences preferences = getActivity().getSharedPreferences("temp", Context.MODE_PRIVATE);
final String hasShown = "hasShown";
if (preferences.getBoolean(hasShown, false)) {
return;
}
AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
.setTitle("This is still in beta!")
.setMessage("Data is not yet finished nor complete. Please help us via Github. Links available in the drawer.")
.setPositiveButton("Ok no problem!", null)
.show();
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
preferences.edit().putBoolean(hasShown, true).apply();
}
});
}
示例3: requestPermissions
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
public static void requestPermissions(
final Activity activity,
int title,
int message,
final int requestCode,
final String... permissions)
{
boolean shouldShowDialog = false;
for (String permission : permissions) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
shouldShowDialog = true;
break;
}
}
if (shouldShowDialog) {
AlertDialog builder = new AlertDialog.Builder(activity).setTitle(title)
.setMessage(message)
.setPositiveButton(android.R.string.ok, null)
.create();
builder.setCanceledOnTouchOutside(false);
builder.show();
builder.setOnDismissListener(new DialogInterface.OnDismissListener()
{
@Override
public void onDismiss(DialogInterface dialog)
{
ActivityCompat.requestPermissions(activity, permissions, requestCode);
}
});
} else {
ActivityCompat.requestPermissions(activity, permissions, requestCode);
}
}
示例4: show
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
public void show() {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(titleRes);
View view = View.inflate(context, R.layout.dialog_enter_text, null);
final EditText input = (EditText) view.findViewById(R.id.editText);
input.setText(value);
input.setSelection(input.getText().length());
if (hint != null) {
input.setHint(hint);
}
input.setInputType(inputType);
builder.setView(view);
builder.setPositiveButton(R.string.button_ok, null);
builder.setNegativeButton(R.string.button_cancel, (dialog, which) -> dialog.cancel());
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(dialog -> {
Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(view1 -> {
input.setError(null);
String newValue = input.getText().toString().trim();
if (TextUtils.isEmpty(newValue) && !allowEmpty) {
input.setError(context.getString(R.string.field_is_required));
input.requestFocus();
} else {
try {
if (validator != null) {
validator.validate(newValue);
}
if (callback != null) {
callback.onChanged(newValue);
}
if (target != null) {
target.setText(newValue);
}
alertDialog.dismiss();
} catch (IllegalArgumentException e) {
input.setError(e.getMessage());
input.requestFocus();
}
}
});
});
alertDialog.setOnDismissListener(onDismissListener);
alertDialog.show();
input.post(() -> {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
});
}