Java tutorial
//package com.java2s; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.view.View; import android.view.WindowManager; import android.widget.EditText; import android.widget.ScrollView; import android.widget.TextView; public class Main { public static Dialog confirm(String title, String message, Context context, DialogInterface.OnClickListener onConfirmListener) { return confirmBuilder(title, context, onConfirmListener).setMessage(message).show(); } public static Dialog confirm(String title, View view, Context context, DialogInterface.OnClickListener onConfirmListener) { Builder dialogBuilder = confirmBuilder(title, context, onConfirmListener).setView(view); if (view instanceof TextView) { ScrollView scrollView = new ScrollView(context); scrollView.addView(view); dialogBuilder.setView(scrollView); } AlertDialog dialog = dialogBuilder.create(); if (view instanceof EditText) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } dialog.show(); return dialog; } private static Builder confirmBuilder(String title, Context context, DialogInterface.OnClickListener onConfirmListener) { Builder builder = new AlertDialog.Builder(context).setTitle(title) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, onConfirmListener); return builder; } }