I'm using ListFragment with ParseQueryAdapter in order to show list of leagues (custom model). I managed to get my desired state except that the loading animation is not showing at all.
It seems like the animation is hidden when the listsAdapter is set (by setListAdapter method), so I set the adapter only after my list is fetched, but the parseQueryAdapter fetches the list only after setting the adapter to a list.
So I found that I can use the setListShown method in order to hide/show the animation, but in my current implementation it doesn't work.
My code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
// Create query factory
ParseQueryAdapter.QueryFactory<League> factory = new ParseQueryAdapter.QueryFactory<League>() {
public ParseQuery<League> create() {
ParseQuery<League> query = League.getQuery();
query.whereEqualTo(League.FIELD_USER, ParseUser.getCurrentUser());
query.orderByDescending(League.FIELD_CREATED_AT);
return query;
}
};
// Create adapter
leagueListAdapter = new LeagueAdapter(getActivity(), factory);
// Loading listener
leagueListAdapter.addOnQueryLoadListener(new ParseQueryAdapter.OnQueryLoadListener<League>() {
@Override
public void onLoading() {
// Show ListFragment's loading animation while loading
setListShown(false);
}
@Override
public void onLoaded(List<League> leagues, Exception e) {
if(e == null){
// Hide loading animation and show the list
setListShown(true);
// Put leagues in the cache
LeaguesCache.getInstance().setCachedLeagues(leagues);
} else {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
// Set fragment's adapter
setListAdapter(leagueListAdapter);
// Dialogs
addLeagueDialog = new addLeagueDialog(this);
}