I'm developing an android app that reads data from API then show these data in multi-choice dialog. However, when I click the button the dialog is empty. I think that maybe the program executes the next lines of code before volley returns the response. I searched a lot but I didn't understand how to fix this, I'm a beginner in using Volley.

Here is the dialog code where I get the data from API:

```
public class LevelsDialog extends DialogFragment {
    ArrayList<String> list = new ArrayList<>();
    static   String[] array;
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        array = getLevels();
        final boolean[] checkedItems = new boolean[array.length];
        builder.setTitle("Select Levels").setMultiChoiceItems(array, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                if(isChecked) {
                    list.add(array[which]);
                    checkedItems[which] =true;
                } else if(list.contains(array[which])) {
                    list.remove(array[which]);
                    checkedItems[which] = false;
                }
            }

        }).setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                for(int i=0 ; i<list.size(); i++)
                Log.e("After", "onClick: "+ list.get(i) );
            }
        });

        return builder.create();
    }

    public String[] getLevels() {
        final ArrayList<String> LevelsList = new ArrayList<>();

        String url = Connection.URL + "/getAllLevels";

        JsonArrayRequest objectRequest = new JsonArrayRequest(
                Request.Method.GET,
                url,
                null,
                new Response.Listener<JSONArray>() {

                    @Override
                    public void onResponse(JSONArray response) {
                        if (response.length() != 0) {
                            int length = response.length();

                            for (int i = 0; i < length; i++) {
                                try {
                                    LevelsList.add(response.get(i).toString());

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                },
                new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("Rest Response Error ", error.toString());
                    }
                });
        Connection.getConnection(getActivity()).addToRequestQueue(objectRequest);

        String[] Levels = LevelsList.toArray(new String[LevelsList.size()]);

        return Levels;
    }
}

```

Any idea? Thanks.