提交片段从活动中onLoadFinished

提交片段从活动中onLoadFinished

本文介绍了提交片段从活动中onLoadFinished的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它加载使用装载机回调服务器的数据列表中的一个活动。我有数据列表伸到延伸

I have an activity which loads a data list from the server using loader callbacks. I have to list out the data into a fragment which extends

SherlockListFragment

我试图用承诺片段

i tried to commit the fragment using

Fragment newFragment   = CategoryFragment.newInstance(mStackLevel,categoryList);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.simple_fragment, newFragment).commit();

在onLoadFinished,它给一个IllegalStateException说

in onLoadFinished and it gives an IllegalStateException saying

java.lang.IllegalStateException: Can not perform this action inside of onLoadFinished

我已经在动作条夏洛特提到的例子,但这些实施例有片段内装载机和不活动

I have referred the example in actionbar sherlock, but those examples have loaders within the fragments and not the activity.

任何人可以帮助我但愿我可以修复它​​无需从片段调用装载机!

Can anybody help me with this o that I can fix it without calling the loader from the fragment!

推荐答案

Atlast,我已经找到了解决这一问题。创建一个手柄设置一个空的消息,并调用处理器onLoadFinished()。在code是与此类似。

Atlast, I have found a solution to this problem. Create a handle setting an empty message and call that handler onLoadFinished(). The code is similar to this.

@Override
public void onLoadFinished(Loader<List<Station>> arg0, List<Station> arg1) {
    // do other actions
    handler.sendEmptyMessage(2);
}

在处理程序,

private Handler handler = new Handler()  { // handler for commiting fragment after data is loaded
    @Override
    public void handleMessage(Message msg) {
        if(msg.what == 2) {
            Log.d(TAG, "onload finished : handler called. setting the fragment.");
            // commit the fragment
        }
    }
};

片段的数量取决于要求

The number of fragments depend on the requirement.

This method can be mainly used in case of stackFragments, where all fragments have different related functions.

这篇关于提交片段从活动中onLoadFinished的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:59