1

我将 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);
}
4

0 回答 0