commit fragment from onLoadFinished within activity

后端 未结 3 1370
一向
一向 2020-12-31 10:57

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

SherlockListFra         


        
3条回答
  •  一生所求
    2020-12-31 11:36

    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> arg0, List arg1) {
        // do other actions
        handler.sendEmptyMessage(2);
    }
    

    In the handler,

    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.
    

提交回复
热议问题