当我在不使用活动的情况下将片段放入dialogfragment时,我收到IllegalStateException。我的设计不是使用活动。在这方面有谁能帮助我?
代码段:
popUpFragment = this;
popUpFragment.dismissPopUp += DismissPopUpDialog;
dialog = new PopUpDialogFragment(popUpFragment, this.GetString(Resource.String.signin_btn_title), HeaderButton.Close, this.Resources.GetDimension(Resource.Dimension.Tablet_Popup_Width), this.Resources.GetDimension(Resource.Dimension.Tablet_Signin_Height), true);
dialog.Show(this.Activity.SupportFragmentManager, "test dialog");
以上代码已在片段的构造函数中使用。我得到的例外是:
06-26 21:58:17.505: W/dalvikvm(4696): JNI WARNING: JNI method called with exception pending
06-26 21:58:17.505: W/dalvikvm(4696): in Lgrocery/droid/fragments/HomeScreenFragment;.n_onClick:(Landroid/view/View;)V (GetMethodID)
06-26 21:58:17.505: W/dalvikvm(4696): Pending exception is:
06-26 21:58:17.505: I/dalvikvm(4696): java.lang.IllegalStateException: Fragment SignInFragment{53aad3b8} not attached to Activity
06-26 21:58:17.505: I/dalvikvm(4696): (raw stack trace not found)
06-26 21:58:17.509: I/dalvikvm(4696): "main" prio=5 tid=1 NATIVE
06-26 21:58:17.509: I/dalvikvm(4696): | group="main" sCount=0 dsCount=0 obj=0xa62e54b0 self=0xb7aea500
06-26 21:58:17.509: I/dalvikvm(4696): | sysTid=4696 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-1216605120
06-26 21:58:17.509: I/dalvikvm(4696): | schedstat=( 3374948563 913984594 3593 ) utm=283 stm=54 core=0
06-26 21:58:17.525: I/dalvikvm(4696): #00 pc 0008f4ad /system/lib/libdvm.so
06-26 21:58:17.525: I/dalvikvm(4696): #01 pc 00073efa /system/lib/libdvm.so
06-26 21:58:17.525: I/dalvikvm(4696): #02 pc 00074024 /system/lib/libdvm.so
06-26 21:58:17.525: I/dalvikvm(4696): #03 pc 0003879a /system/lib/libdvm.so
06-26 21:58:17.525: I/dalvikvm(4696): #04 pc 0003d788 /system/lib/libdvm.so
06-26 21:58:17.525: I/dalvikvm(4696): #05 pc 00029d28 <unknown>
06-26 21:58:17.525: I/dalvikvm(4696): at grocery.droid.fragments.HomeScreenFragment.n_onClick(Native Method)
06-26 21:58:17.525: I/dalvikvm(4696): at grocery.droid.fragments.HomeScreenFragment.onClick(HomeScreenFragment.java:81)
06-26 21:58:17.525: I/dalvikvm(4696): at android.view.View.performClick(View.java:4084)
06-26 21:58:17.525: I/dalvikvm(4696): at android.view.View$PerformClick.run(View.java:16966)
06-26 21:58:17.525: I/dalvikvm(4696): at android.os.Handler.handleCallback(Handler.java:615)
06-26 21:58:17.525: I/dalvikvm(4696): at android.os.Handler.dispatchMessage(Handler.java:92)
06-26 21:58:17.525: I/dalvikvm(4696): at android.os.Looper.loop(Looper.java:137)
答案 0 :(得分:0)
Fragment和DialogFragment必须使用Activity实现让活动将信息传递给其他片段,或者您可以使用AlertDialog.Builder。看看这里:Dialogs