0

アラートダイアログでリンク可能なテキストを作成し、次のように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:ERROR / 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:アクティビティcom.blah.MainActivityが、元々ここに追加されたウィンドウcom.android.internal.policy.impl.PhoneWindow$DecorView@405d7010をリークしました

これは、リンクがクリックされる前にアラートが閉じられないためだと思います。これを回避する方法はありますか?エラーをスローしたくない。

4

1 に答える 1

1

アクティビティが破棄される前にダイアログを破棄する場合は、onDestroy()イベントをオーバーライドできます。

@Override
public void onDestroy(){
    //Your dialog disposal code here

    super.onDestroy(); //Make sure you include this at the end.
}

お役に立てば幸い

于 2011-08-20T00:20:07.130 に答える