mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Added: Support for MessageDialogUtils.showMessage() to receive positive and negative button OnClickListeners
This commit is contained in:
@@ -22,9 +22,33 @@ public class MessageDialogUtils {
|
|||||||
* @param onDismiss The {@link DialogInterface.OnDismissListener} to run when dialog is dismissed.
|
* @param onDismiss The {@link DialogInterface.OnDismissListener} to run when dialog is dismissed.
|
||||||
*/
|
*/
|
||||||
public static void showMessage(Context context, String titleText, String messageText, final DialogInterface.OnDismissListener onDismiss) {
|
public static void showMessage(Context context, String titleText, String messageText, final DialogInterface.OnDismissListener onDismiss) {
|
||||||
|
showMessage(context, titleText, messageText, null, null, null, null, onDismiss);
|
||||||
|
}
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Theme_AppCompat_Light_Dialog)
|
/**
|
||||||
.setPositiveButton(android.R.string.ok, null);
|
* Show a message in a dialog
|
||||||
|
*
|
||||||
|
* @param context The {@link Context} to use to start the dialog. An {@link Activity} {@link Context}
|
||||||
|
* must be passed, otherwise exceptions will be thrown.
|
||||||
|
* @param titleText The title text of the dialog.
|
||||||
|
* @param messageText The message text of the dialog.
|
||||||
|
* @param positiveText The positive button text of the dialog.
|
||||||
|
* @param onPositiveButton The {@link DialogInterface.OnClickListener} to run when positive button
|
||||||
|
* is pressed.
|
||||||
|
* @param negativeText The negative button text of the dialog. If this is {@code null}, then
|
||||||
|
* negative button will not be shown.
|
||||||
|
* @param onNegativeButton The {@link DialogInterface.OnClickListener} to run when negative button
|
||||||
|
* is pressed.
|
||||||
|
* @param onDismiss The {@link DialogInterface.OnDismissListener} to run when dialog is dismissed.
|
||||||
|
*/
|
||||||
|
public static void showMessage(Context context, String titleText, String messageText,
|
||||||
|
String positiveText,
|
||||||
|
final DialogInterface.OnClickListener onPositiveButton,
|
||||||
|
String negativeText,
|
||||||
|
final DialogInterface.OnClickListener onNegativeButton,
|
||||||
|
final DialogInterface.OnDismissListener onDismiss) {
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Theme_AppCompat_Light_Dialog);
|
||||||
|
|
||||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
|
||||||
View view = inflater.inflate(R.layout.dialog_show_message, null);
|
View view = inflater.inflate(R.layout.dialog_show_message, null);
|
||||||
@@ -40,6 +64,13 @@ public class MessageDialogUtils {
|
|||||||
messageView.setText(messageText);
|
messageView.setText(messageText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (positiveText == null)
|
||||||
|
positiveText = context.getString(android.R.string.ok);
|
||||||
|
builder.setPositiveButton(positiveText, onPositiveButton);
|
||||||
|
|
||||||
|
if (negativeText != null)
|
||||||
|
builder.setNegativeButton(negativeText, onNegativeButton);
|
||||||
|
|
||||||
if (onDismiss != null)
|
if (onDismiss != null)
|
||||||
builder.setOnDismissListener(onDismiss);
|
builder.setOnDismissListener(onDismiss);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user