send message to Calling listFragment from Custom Adapter

有些话、适合烂在心里 提交于 2019-12-11 19:23:30

问题


I have a ListFragment , which will display a list of news feed items.

I'm doing an asyncTask to get 20 feeds initially, then I need to do another call to get next 20 feeds , only if the user has done reading first 20.

I.e My Adapter should notify my fragment that it needs next feeds.

This is my present code (AsyncTask of myListFragment) .

@Override
protected void onPostExecute(Object result) {


    List<PublicFeed> feedItemsList = (List<PublicFeed>) result;

    listener = new ScrollListener();
    getListView().setOnScrollListener(listener);
    getListView().setDividerHeight(2);


    myCustomAdapter = new CustomAdapter(myContext, listener,
            feedItemsList);
    setListAdapter(myCustomAdapter);


}
  • Is this the right way of implementation ( practice ) ?
  • The code is working fine now. I'm able to get 20 feeds and display them. But I don't know how do I notify the FeedFragment for next AsyncTask Call From myCustomAdapter?
  • once I receve such a call, I can do the asyncTask from myFragment, and update the dataset. Then call notifyDataSetChanged() on my adapter.

Please review. And suggest an implementation.

Thank YOU

EDIT -1

my CustomAdapterextends BaseAdapter


回答1:


Change your adapter's constructor so that you can pass the reference of your fragment to your adapter. Then you can make a callback to your fragment's methods from your adapter.



来源:https://stackoverflow.com/questions/18502653/send-message-to-calling-listfragment-from-custom-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!