问题
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 CustomAdapter
extends 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