2

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();

Not going onSuccess method when getting users data from QBUsers.getUsersByIDs() using quickblox example in android?

Azhar osws
  • 188
  • 1
  • 8

1 Answers1

2

Its not showing because you are not supplying any value into the query:

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

You should add an id or several ids to this list before the query can search to see if the user is present and return the QBUser in the onSuccess method. An example of a correct way of doing it is:

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();

If there is a user with this id then it will return the user in the onSuccess() method. Hope this helps.

Norris Boateng
  • 357
  • 1
  • 5
  • 18
  • Thanks. But I have added id later. But I am getting error on my list adapter. The problem I am facing on, where should I declare my list adapter. Because I getting my users(Arraylist) empty.Though I have later declared public users (Arraylist). – Azhar osws Feb 09 '16 at 05:44
  • Don't really get you but its always advisable – Norris Boateng Feb 09 '16 at 08:39
  • I have added id. I am getting all that data in arraylist. But when i add this arraylist in my adapter then my listview is not displaying anything. – Azhar osws Feb 09 '16 at 11:59
  • It's advisable to execute setAdapter in the ui thread. So either create a method to set the adapter and call it inside onSuccess or do runOnUIThread inside onSuccess. I would recommend using the method – Norris Boateng Feb 09 '16 at 12:13
  • Yeah thanks. Actually I was declaring this method on onCreateView(). So it was giving me error on getActivity(). Now I have changed getActivity to context and hence its working fine. Thanks – Azhar osws Feb 10 '16 at 07:02