我的功能:
private void buildEmptyLessonList()
{
final Context ctx = this;
LinearLayout topContainer = findViewById(R.id.LessonList);
topContainer.removeAllViews();
LinearLayout.LayoutParams llparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ScrollView svContainer = new ScrollView(ctx);
svContainer.setLayoutParams(llparams);
topContainer.addView(svContainer);
LinearLayout tl = new LinearLayout(ctx);
tl.setId(generateViewId());
tl.setOrientation(LinearLayout.VERTICAL);
tl.setLayoutParams(llparams);
svContainer.addView(tl);
ft.add(tl.getId(), NoLessons.newInstance(), "NoLessons");
ft.commit();
//getFragmentManager().executePendingTransactions();
}
如果我经常(比每秒快一次)调用此函数,我会收到错误:
java.lang.IllegalArgumentException:
at android.app.FragmentManagerImpl.moveToState (FragmentManager.java:987)
at android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1171)
at android.app.BackStackRecord.run (BackStackRecord.java:815)
at android.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1582)
at android.app.FragmentManagerImpl$1.run (FragmentManager.java:483)
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:6692)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)
使用“getChildFragmentTransaction()”不会产生任何影响。