2011-08-19 65 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:錯誤/ WindowManager(5886):活動 com.blah.MainActivity泄漏窗口 [email protected] 最初是在這裏添加08- 19 19:40:55.753: 錯誤/ WindowManager(5886):android.view.Wind owLeaked:活動 com.blah.MainActivity滲漏窗口 [email protected]是 原來這裏加入

我想這是因爲該警報沒有被駁回鏈接被點擊之前。 有沒有辦法解決這個問題?我不想拋出任何錯誤。

回答

1

如果你想在activity被銷燬之前,處置該對話框,您可以覆蓋的onDestroy()事件

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

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

希望幫助