0

Possible Duplicate:
Android: Clickable hyperlinks in AlertDialog

Hi, I have created an AlertDialog with two buttons (positive and negative) along with message text. Both the buttons are performing some action already and I want to hyper link the message text in AlertDialog box. Can anyone please help me with how to do this?

Community
  • 1
  • 1
Droidand
  • 176
  • 1
  • 4
  • 10

1 Answers1

2

You've still got 1 more button (neutral) to play with if you wanted...
Otherwise, I would suggest reading this question.

This is how I have accomplished it though:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.app_name)
                .setIcon(R.drawable.dialog_icon)
               .setMessage(R.string.welcome_text)
               .setCancelable(true)
               .setNegativeButton(R.string.okay, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                   }
               });

        AlertDialog welcomeAlert = builder.create();
        welcomeAlert.show();
        // Make the textview clickable. Must be called after show()
        ((TextView)welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());

I have used regular <a href=".."></a> formatting in my strings.xml

The only thing I don't like about my current solution is that it makes all of the text clickable and not just the links.

Community
  • 1
  • 1
Kavi
  • 3,880
  • 2
  • 26
  • 23
  • 1
    As the AlertDialog is a built-in function, the android.R.id.message is the (otherwise hidden) reference given to the text/message area of the Dialog by the SDK. This is the area of the Dialog we want to make clickable. – Kavi May 25 '11 at 15:27
  • If you set the Color of the text to setTextColor(Color.WHITE) the flickering effect is gone. – Informatic0re Aug 27 '14 at 13:27