我試圖創建一個AlertDialog,通過使用生成器和設置自定義視圖。當我試圖誇大onCreateDialog內的看法,我得到的StackOverflowError ..StackOverflowError當試圖膨脹一個DialogFragment內的AlertDialog的自定義佈局
下面是代碼達到它返回到onCreateDialog點:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.enter_time);
LinearLayout outerLayout = (LinearLayout) getLayoutInflater(savedInstanceState)
.inflate(R.layout.time_entry_dialog, null);
...
}
這裏是logcat的輸出:
02-28 22:30:04.220: E/AndroidRuntime(4250): FATAL EXCEPTION: main
02-28 22:30:04.220: E/AndroidRuntime(4250): java.lang.StackOverflowError
02-28 22:30:04.220: E/AndroidRuntime(4250): at android.app.Activity.getSystemService(Activity.java:4009)
02-28 22:30:04.220: E/AndroidRuntime(4250): at android.view.LayoutInflater.from(LayoutInflater.java:210)
02-28 22:30:04.220: E/AndroidRuntime(4250): at android.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:75)
02-28 22:30:04.220: E/AndroidRuntime(4250): at com.android.internal.app.AlertController$AlertParams.<init>(AlertController.java:812)
02-28 22:30:04.220: E/AndroidRuntime(4250): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:374)
02-28 22:30:04.220: E/AndroidRuntime(4250): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:359)
02-28 22:30:04.220: E/AndroidRuntime(4250): at com.sweatyreptile.chee.runtimetracker.TimeEntryDialogFragment.onCreateDialog(TimeEntryDialogFragment.java:18)
02-28 22:30:04.220: E/AndroidRuntime(4250): at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:295)
02-28 22:30:04.220: E/AndroidRuntime(4250): at com.sweatyreptile.chee.runtimetracker.TimeEntryDialogFragment.onCreateDialog(TimeEntryDialogFragment.java:21)
02-28 22:30:04.220: E/AndroidRuntime(4250): at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:295)
02-28 22:30:04.220: E/AndroidRuntime(4250): at com.sweatyreptile.chee.runtimetracker.TimeEntryDialogFragment.onCreateDialog(TimeEntryDialogFragment.java:21)
02-28 22:30:04.220: E/AndroidRuntime(4250): at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:295)
...etc
編輯:我發現這個線路中的DialogFragment.getLayoutInflater()源:
mDialog = onCreateDialog(savedInstanceState);
因此..如果我無法在onCreateDialog中獲得LayoutInflator而沒有導致無限遞歸,那麼如何爲定製AlertDialog充氣視圖?
你在'time_entry_dialog'裏有什麼?也不要害怕發佈stacktrace與例外。 – Luksprog 2013-03-01 06:27:57
請添加您的Logcat輸出 – 2013-03-01 06:28:09
我添加了LogCat輸出。 @Luksprog,'time_entry_dialog'只是一個以重心爲中心的LinearLayout – 2013-03-01 06:35:02