In the onClick
method I have to add the call to the requestCoffe
method
but I do not know how to do it
private void requestCoffe(){
RequestQueue queue= Volley.newRequestQueue(this);
JsonArrayRequest arrayRequest=new JsonArrayRequest(Request.Method.GET,
URL, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
coffees=new ArrayList<>();
try {
for (int i=0; i < response.length(); i++){
Coffee coffee=new Coffee(response.getJSONObject(i));
coffees.add(coffee);
}
adapter=new CoffeeAdapter(coffees, MainActivity.this); //Modificar la creación del Adapter, agregando
// la referencia a la clase como segundo argumento.
recyclerCoffee.setAdapter(adapter);
} catch (JSONException e){
e.printStackTrace();
}
}
}, new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
Toast.makeText(MainActivity.this, "No se puede conectar",
Toast.LENGTH_SHORT).show();
}
});
queue.add(arrayRequest);
}
public void onClick(View view) {
}