没有从quickblox示例中获取用户列表信息

时间:2016-02-04 11:19:55

标签: android quickblox-android

final ListView opponentsList = (ListView) view.findViewById(R.id.opponentsList);
        ArrayList<Integer> userIds = new ArrayList<>();
        QBUsers.getUsersByIDs(userIds, new QBPagedRequestBuilder(userIds.size(), 1), new QBEntityCallbackImpl<ArrayList<QBUser>>() {
            @Override
            public void onSuccess(ArrayList<QBUser> results, Bundle params) {
                super.onSuccess(results,params);
                List<QBUser> users = new ArrayList<>(results.size());
                for (QBUser result : results)
                {
                    // There mus be a more efficient, or at least better looking, way of doing this...
                    QBUser user = new QBUser();
                    user.setId(result.getId());
                    user.setLogin(result.getFullName());
                    users.add(user);
                }

                int i = searchIndexLogginedUser(users);
                if (i >= 0)
                    users.remove(i);

                // Prepare users list for simple adapter.
                //
                opponentsAdapter = new OpponentsAdapter(getActivity(), users);
                opponentsList.setAdapter(opponentsAdapter);
            }
        });
        progresDialog.dismiss();

在Android中使用quickblox示例从QBUsers.getUsersByIDs()获取用户数据时没有使用onSuccess方法?

1 个答案:

答案 0 :(得分:2)

它没有显示,因为您没有在查询中提供任何值:

ArrayList<Integer> userIds = new ArrayList<>();

在查询可以搜索以查看用户是否存在并在onSuccess方法中返回QBUser之前,您应该向此列表添加一个或多个ID。 正确的方法的一个例子是:

ArrayList<Integer> userIds = new ArrayList<>();
userIds.add(123456);
QBUsers.getUsersByIDs(userIds, new QBPagedRequestBuilder(userIds.size(), 1), new QBEntityCallbackImpl<ArrayList<QBUser>>() {
        @Override
        public void onSuccess(ArrayList<QBUser> results, Bundle params) {
            super.onSuccess(results,params);
            List<QBUser> users = new ArrayList<>(results.size());
            for (QBUser result : results)
            {
                // There mus be a more efficient, or at least better looking, way of doing this...
                QBUser user = new QBUser();
                user.setId(result.getId());
                user.setLogin(result.getFullName());
                users.add(user);
            }

            int i = searchIndexLogginedUser(users);
            if (i >= 0)
                users.remove(i);

            // Prepare users list for simple adapter.
            //
            opponentsAdapter = new OpponentsAdapter(getActivity(), users);
            opponentsList.setAdapter(opponentsAdapter);
        }
    });
    progresDialog.dismiss();

如果有一个具有此id的用户,则它将在onSuccess()方法中返回该用户。希望这会有所帮助。