我试图用FragmentActivity与ViewPager显示的动态列表Fragments.有很多关于如何做静态版本的例子.我的问题是我显示的列表需要动态加载,也可以根据用户输入(添加/删除)进行更改.我正在尝试使用自定义android.support.v4.content.Loader来加载我可用于构建列表的数据集.
在我的设置中一切正常,直到我想要更新适配器并发出FragmentStatePagerAdapter#notifyDataSetChanged()调用此时执行此代码(来自FragmentStatePagerAdapter)
public void finishUpdate(View container)
{
if(mCurTransaction != null)
{
mCurTransaction.commit(); // BANG!!! The exception is thrown
mCurTransaction = null;
mFragmentManager.executePendingTransactions();
}
}
Run Code Online (Sandbox Code Playgroud)
事务提交失败并显示以下消息:
java.lang.IllegalStateException: Can not perform this action inside of onLoadFinished
因为在FragmentManagerImpl这段代码中执行:
private void checkStateLoss() {
if (mStateSaved) {
throw new IllegalStateException(
"Can not perform this action after onSaveInstanceState");
}
if (mNoTransactionsBecause != null) {
throw new IllegalStateException(
"Can not perform this action …Run Code Online (Sandbox Code Playgroud)