alert dialog with SpannableString - Android User Interface

Android examples for User Interface:Dialog

Description

alert dialog with SpannableString

Demo Code


//package com.java2s;
import android.app.AlertDialog;

import android.content.Context;

import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;

import android.widget.TextView;

public class Main {
    public static void alert(String title, String message, Context context) {
        alert(title, message, context, false);
    }//from   w  w w .  j a va 2s. com

    public static void alert(String title, String message, Context context,
            boolean linksClickable) {
        SpannableString spannableString = new SpannableString(message);
        if (linksClickable) {
            Linkify.addLinks(spannableString, Linkify.ALL);
        }

        AlertDialog dialog = new AlertDialog.Builder(context)
                .setTitle(title).setMessage(spannableString)
                .setPositiveButton(android.R.string.ok, null).create();
        dialog.show();
        // Make text links clickable
        if (linksClickable) {
            ((TextView) dialog.findViewById(android.R.id.message))
                    .setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
}

Related Tutorials