如何在视图寻呼机内部的嵌套片段中刷新子片段?
您好, 我想刷新我当前的片段,我在项目结构中有这个概念和逻辑,http://tausiq.wordpress.com/2014/06/06/android-multiple-fragments-stack-in-each-viewpager-tab/
当我从孩子回到父母时,我想刷新我的混合父片段,
主要问题是当我要回来的时候,this
总是空的,意味着getActivity
没有意思,
我试过这段代码,但它不能正常工作
09-25 12:48:14.002: E/AndroidRuntime(18584): FATAL EXCEPTION: main
09-25 12:48:14.002: E/AndroidRuntime(18584): Process: com.bbits.nyautogiant, PID: 18584
09-25 12:48:14.002: E/AndroidRuntime(18584): java.lang.IllegalStateException: Activity has been destroyed
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1382)
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
09-25 12:48:14.002: E/AndroidRuntime(18584): at com.bbits.nyautogiant.fragments.SearchResultFragment.refreshListBaseOnRefine(SearchResultFragment.java:1329)
09-25 12:48:14.002: E/AndroidRuntime(18584): at com.bbits.nyautogiant.NYAutoGiantActivity.setTitle(NYAutoGiantActivity.java:356)
09-25 12:48:14.002: E/AndroidRuntime(18584): at com.bbits.nyautogiant.fragments.RefineFragment$2.onClick(RefineFragment.java:124)
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.view.View.performClick(View.java:4424)
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.view.View$PerformClick.run(View.java:18383)
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.os.Handler.handleCallback(Handler.java:733)
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.os.Handler.dispatchMessage(Handler.java:95)
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.os.Looper.loop(Looper.java:137)
09-25 12:48:14.002: E/AndroidRuntime(18584): at android.app.ActivityThread.main(ActivityThread.java:4998)
09-25 12:48:14.002: E/AndroidRuntime(18584): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 12:48:14.002: E/AndroidRuntime(18584): at java.lang.reflect.Method.invoke(Method.java:515)
09-25 12:48:14.002: E/AndroidRuntime(18584): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
09-25 12:48:14.002: E/AndroidRuntime(18584): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
09-25 12:48:14.002: E/AndroidRuntime(18584): at dalvik.system.NativeStart.main(Native Method)
SearchResultFragment
是我最受欢迎的父片段,
refreshCode
SearchResultFragment addSearchResultFragment = new SearchResultFragment();
getChildFragmentManager().beginTransaction().detach(SearchResultFragment.this).replace(R.id.frmlay_search_result, addSearchResultFragment).attach(addSearchResultFragment)
.addToBackStack(null).commit();
这是我的即将到来的父片段xml。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frmlay_search_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.SearchResultFragment" >
<RelativeLayout
android:id="@+id/rel_main_cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgound" >
android:id="@+id/btn_sr_comaprechk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/btn_sr_comaprechk" />
</RelativeLayout>
</FrameLayout>