2011-08-19 5 views
0

私は警告ダイアログでリンク可能なテキストを作成し、TextViewののクリッカブルを作る、このようにしました:AlertDialogのリークウィンドウにリンクしますか?

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がウィンドウをリークしました [email protected] が最初にここに追加されました08- 19 19:40:55.753: ERROR/WindowManager(5886):android.view.Wind owLeaked:活動 com.blah.MainActivityが漏れた は、もともと私は警告が却下されていないためであると考え、ここで

に追加されたことをウィンドウ [email protected]リンクがクリックされる前に これを回避する方法はありますか?私は何のエラーも投げないことを好むだろう。

答えて

1

アクティビティが破棄される前にダイアログを配置したい場合、あなたは

を助けonDestroy()イベント

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

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

希望をオーバーライドすることができます

関連する問題