我在警告对话框中创建了一个可链接的文本,并使 TextView 可点击,如下所示:
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());
这有效,但是当它被点击时,它会在 logcat 中产生一个错误:
08-19 19:40:55.753: 错误/WindowManager(5886): 活动 com.blah.MainActivity 已泄露窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@405d7010 最初添加在这里 08-19 19: 40:55.753: ERROR/WindowManager(5886): android.view.WindowLeaked: Activity com.blah.MainActivity 泄露了最初添加在这里的窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@405d7010
我认为这是因为在单击链接之前没有解除警报。有没有办法解决?我不想抛出任何错误。