本文介紹了創建自定義對話框時出現問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我在創建自定義對話框時遇到問題.但我沒有發現失敗.希望有人可以幫助我...
I have a problem creating a custom dialog. But I don't find the failure. Hopefully anybody can help me ...
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG_ABOUT_ID:
dialog = buildAboutDialog();
break;
default:
dialog = null;
}
return dialog;
}
...
public Dialog buildAboutDialog() {
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.about_dialog);
dialog.setTitle("About this application");
return dialog;
}
導致以下錯誤:
12-30 19:27:02.593: ERROR/AndroidRuntime(383): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
我檢查了返回的對話框是否 == null - 但不是.
I checked if the returned dialog == null - but it isn't.
我還嘗試了 http:///developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
推薦答案
發現,對話框需要用
Dialog dialog = new Dialog(this);
而不是
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
我不知道為什么.也許有人可以向我解釋一下?
I don't exactly know why. Perhaps anybody can explain it to me?
這篇關于創建自定義對話框時出現問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!