Show Long Message in AlertDialog

android, android-alertdialog, android-dialog

Solution

Change

dialog.setTitle(message);

to

dialog.setMessage(message);

and if you want to center align the text, you'll have to create a textview like in the following example:

    AlertDialog.Builder dialog = new AlertDialog.Builder(con);
    dialog.setTitle(message);
    dialog.setPositiveButton(" OK ", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();

        }
    });
    dialog.show();

// Must call show() prior to fetching text view
TextView messageView = (TextView)dialog.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER);

taken from: Center message in android dialog box

Problem

I am trying to display an lengthy message in Default AlertDialog with following code. ``` public static void showAlert(String message, Context con) { AlertDialog.Builder dialog = new AlertDialog.Builder(con); dialog.setTitle(message); dialog.setPositiveButton(" OK ", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); dialog.show(); } ``` But when I pass long message Alert Dialog does not display full message. Can I align text of Dialog by center. I dont want to use Custom Dialog.

Original source

Related problems