我试图使用FragmentActivity
和ViewPager
来显示动态列表Fragments
。有很多关于如何做静态版本的例子。我的问题是我显示的列表需要动态加载,也可以根据用户输入(添加/删除)进行更改。我正尝试使用自定义的android.support.v4.content.Loader
加载可用于构建我的列表的数据集。Android - 使用FragmentActivity + Loader更新FragmentStatePagerAdapter的问题
一切顺利在我的设置很好,直到我去点时,我想更新适配器,并发出此时该代码被执行(从FragmentStatePagerAdapter
)FragmentStatePagerAdapter#notifyDataSetChanged()
呼叫
public void finishUpdate(View container)
{
if(mCurTransaction != null)
{
mCurTransaction.commit(); // BANG!!! The exception is thrown
mCurTransaction = null;
mFragmentManager.executePendingTransactions();
}
}
提交失败与交易此消息:
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 inside of " + mNoTransactionsBecause);
}
}
事实证明,mNoTransactionsBecause
值不为空,它是在LoaderManagerImpl.LoaderInfo
设定时,返回的结果回onLoadFinished
我一直在寻找各种变量试图以某种方式改变tramsaction.commit()
到transaction.commitAllowingStateLoss()
但一切相关交易似乎是私人的,或者至少是包裹保护的。
如果我可以做我需要做的事情(以及如何做),有人可以给我一个总体想法吗?
只是要注意的是我的代码工作正常,如果不是使用装载机我的AsyncTask
你已经能够找出正确的方法用装载机做到这一点?我面临同样的问题。我可以使用'transaction.commitAllowingStateLoss()'来实现它的功能,但是知道Google希望我们做什么仍然很好......似乎应该有一种在加载数据后执行片段事务的方法使用加载程序... – ashughes
我通常放弃了这一点,并使用ModernTaskLoader以限制汇集 – Bostone
什么是ModernTaskLoader?在任何地方都找不到任何信息... – ashughes