I have a snippet that contains a request to display information about the user's groups.
The problem is that if I print an arrayid outside of the query, then an empty arrayid . And if the request is all good. What could be the reason? Thank!
public class fragment extends Fragment { private static final int LAYOUT = R.layout.fragment; private View view; ArrayList<String> arrayid = new ArrayList<>(); @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(LAYOUT,container,false); VKRequest vkRequest = VKApi.groups().get(VKParameters.from(VKApiConst.EXTENDED, 1, "name")); vkRequest.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); System.out.println(response.responseString); try { JSONObject jsonObject = (JSONObject) response.json.get("response"); JSONArray jsonArray = (JSONArray) jsonObject.get("items"); System.out.println("ssshsh"+jsonArray); for (int i = 0; i<jsonArray.length();i++){ JSONObject name = (JSONObject) jsonArray.get(i); arrayid.add(name.getString("id")); } } catch (JSONException e) { e.printStackTrace(); } //если вывожу тут, то все работает System.out.println(Arrays.asList(arrayid)); } }); //если вывожу тут то выводится пустой arrayid } }