我正在尝试刷新选定的微调器项目的第一个选项卡,但它显示错误没有查看发现异常显示我何时尝试调用相同的片段。
刷新相同的片段代码:
DashBoardFragment currentFragment = new DashBoardFragment();
FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
//fragTransaction.detach(currentFragment);
//fragTransaction.attach(currentFragment);
fragTransaction.replace(R.id.home_container, currentFragment);
fragTransaction.commit();
12-30 10:58:34.222 11811-11811/com.cashpundit.cashpundit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cashpundit.cashpundit, PID: 11811
java.lang.IllegalArgumentException: No view found for id 0x7f0c0071 (com.cashpundit.cashpundit:id/home_container) for fragment DashBoardFragment{c2b9283 #2 id=0x7f0c0071}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1098)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1671)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:532)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
答案 0 :(得分:0)
public void Refresh() {
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
List<Fragment> fragments = fragmentManager.getFragments();
for (Fragment fragment : fragments) {
if (fragment != null && fragment.isVisible()) {
if (fragment instanceof SummaryReportsFragment) {
Toast.makeText(getContext(), "Yes", Toast.LENGTH_LONG).show();
FragmentTransaction fragTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragTransaction.detach(fragment);
fragTransaction.attach(fragment);
fragTransaction.commit();
}
}
}
}