Cursoring runs into infinite while loop

android

#1

Hi, i’m a total newbie in java programming so sorry. Below is my code using cursor to access the followers of a specific user, it runs into an infinite loop, i understand that the api is running in async but how do i solve this problem? (Cursor is initialised as global variable with value -1). Everything worked before i added cursor but it only returns 20 results

  private List<TwitterFollowers> fetchResults2(Response<FollowersResponseModel> response) {
    FollowersResponseModel responseModel = response.body();
    return responseModel.getResults();
}

    private long fetchResults3(Response<FollowersResponseModel> response) {
    FollowersResponseModel responseModel = response.body();
    Log.e("lol",String.valueOf(responseModel.getNextCursor()));
    return responseModel.getNextCursor();
}

    private void loadTwitterFollowers() {
    MyTwitterApiClient myTwitterApiClient = new MyTwitterApiClient(twitterSession);
    do {
    myTwitterApiClient.getCustomTwitterService2().list(loggedUserTwitterId, cursor).enqueue(new retrofit2.Callback<FollowersResponseModel>() {
        @Override
        public void onResponse(Call<FollowersResponseModel> call, Response<FollowersResponseModel> response) {
            Log.e("onResponse",response.toString());
            twitterFollowers = fetchResults2(response);
            getActivity().setTitle(String.valueOf(twitterFollowers.size())+ " Followers");
            cursor = fetchResults3(response);

            Log.e("onResponse","twitterfollowers:"+twitterFollowers.size());
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onFailure(Call<FollowersResponseModel> call, Throwable t) {
            Log.e("onFailure",t.toString());
        }

    });
    }
    while (cursor != 0);
}

#2

can you solve it? i face the same problem


#3

nope