ArrayList being empty after adding elements
<p>I have this android code which bring a JSON from a server and fill an ArrayList from that JSON
I checked the size of the ArrayList "meals" inside the onresponse void it gives me 1 but when i check it after the StringRequest object i get 0 items .
meals is defined in global scope and initialized inside the oncreateview function
The Code:</p>

<pre><code>               public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) {
// Inflate the layout for this fragment
Log.i("debug","on create view");
View view =inflater.inflate(R.layout.fragment_meal_list,container,false);
ListView List ;
meals=new ArrayList&lt;meal&gt;();
String url="http://syriankitchen.tk/get_recent.php";
StringRequest mealsrequest = new StringRequest(Request.Method.GET, url, new Response.Listener&lt;String&gt;() {

    @Override
    public void onResponse(String response) {
        try{
            JSONObject object= new JSONObject(response);
            JSONArray mealsArray = object.getJSONArray("result");
            for(int i=0;i&lt;mealsArray.length();i++){
                JSONObject cur = mealsArray.getJSONObject(i);
                int id= cur.getInt("id");
                String name= cur.getString("name");
                String description = cur.getString("description");
                int price = cur.getInt("price");
                meals.add(new meal(id,name,price,description));
            }
            Log.i("debug","meals size = "+meals.size());
        }
        catch(JSONException e){
            e.printStackTrace();
        }
    }
},new Response.ErrorListener(){
    @Override
    public void onErrorResponse(VolleyError error) {
        Toast.makeText(getActivity(),error.getMessage(),Toast.LENGTH_SHORT).show();
    }
});
Volley.newRequestQueue(getActivity()).add(mealsrequest);
ArrayList&lt;String&gt; strs=new ArrayList&lt;String&gt;();
String mealsnames[]=new String[meals.size()];
for(int i=0;i&lt;meals.size();i++)strs.add(meals.get(i).getName());
strs.toArray(mealsnames);
Log.i("debug","meals ou size "+meals.size());
CustomList  adapter = new CustomList(getActivity(),mealsnames,meals);
List = (ListView)view.findViewById(R.id.list);
List.setAdapter(adapter);
</code></pre>