我正在使用ListFragment和ParseQueryAdapter来显示联赛列表(自定义模型)。 我设法得到了我想要的状态,除了加载动画根本没有显示。
在设置listsAdapter时(通过setListAdapter方法)似乎隐藏了动画,所以我只在获取列表后才设置适配器,但是只有在将适配器设置为列表后,parseQueryAdapter才会获取列表。
所以我发现我可以使用setListShown方法隐藏/显示动画,但在我目前的实现中它不起作用。
我的代码:
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);
}