I’ve created a linkable text in an alert dialog, and make the TextView clickable, like this:
final SpannableString noRecords = new SpannableString("Sorry, no records could be found, please try again, or contact us at 867-5309");
Linkify.addLinks(noRecords);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Records Found")
.setMessage(noRecords)
.setCancelable(true)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
((TextView)alert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
This works, however when it’s clicked it produces an error in logcat:
08-19 19:40:55.753: ERROR/WindowManager(5886): Activity
com.blah.MainActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@405d7010 that
was originally added here 08-19 19:40:55.753:
ERROR/WindowManager(5886): android.view.WindowLeaked: Activity
com.blah.MainActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@405d7010 that
was originally added here
I think this is because the alert is not dismissed before the link is clicked.
Is there any way around this? I’d prefer not to be throwing any errors.
If you want to dispose the dialog before the activity is destroyed, you can override the onDestroy() event
Hope that helps