相关疑难解决方法(0)

Android - 使用FragmentActivity + Loader更新FragmentStatePagerAdapter的问题

我试图用FragmentActivityViewPager显示的动态列表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)

android android-viewpager

16
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-viewpager ×1