I have a SwipeRefreshLayout with a listview, so when the user swipes it, I want the app to retrieve json data from a rest server (PHP), parse it, put the data inside the adapter and show the result inside the listview. My question is regarding the "retrieve json data from a rest server (PHP) as a result of swiping".
I read about SyncAdapter but as I understand, it works only inside a service?
Should the swiping call an ASyncTask to retrieve and parse the data? If so, how to connect it back to the adapter that is attached to the listview?
Any hint or examples will be very helpful, even a link to a site that can explain the process will do.
Here is the code I have so far:
View rootView = inflater.inflate(R.layout.s_feed, container, false);
sFeed = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container);
sFeed.setOnRefreshListener(this);
sFeed.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
lvings = (ListView) rootView.findViewById(R.id.lvings);
???
FeedItemAdapter feedItemAdapter = new FeedItemAdapter(R.layout.s_feed_item, feedItem);
lvings.setAdapter(feedItemAdapter);
???
and the refresh part:
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
getItems();
}
}, 5000);
}
private void getItems() {
//call api using asynctask? how to connect to adapter?
if (sFeed.isRefreshing()) sFeed.setRefreshing(false); <<< should be at the end of asynctask?
}