Android Get JSON Data Using Volley Library

PassJsonUrl to this function
Download VolleyLibray



public void sendRequestMovie(String JSON_URL){

showpDialog();
 
StringRequest stringRequest = new StringRequest(JSON_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
ShowJSONMovie(response);
  }
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_LONG).show();
Log.w("error", error.getMessage());
Toast.makeText(getActivity(), "Server Not Reponding", Toast.LENGTH_LONG).show();

hidepDialog();
}
});

RequestQueue requestQueue = Volley.newRequestQueue(ctx);
requestQueue.add(stringRequest);
  }

private void ShowJSONMovie(String json) {
// TODO Auto-generated method stub
JSONObject jsonObject=null;
JSONArray users = null;
try {
jsonObject = new JSONObject(json);
users = jsonObject.getJSONArray("List");//JSON Arrayname

for(int i=0;i<users.length();i++){
JSONObject c = users.getJSONObject(i);
 
HashMap<String,String> mydata=new HashMap<String, String>();

mydata.put("name",c.getString("name"));
mydata.put("permalink",c.getString("permalink"));
mydata.put("poster_url",c.getString("poster_url"));


mylistmovie.add(mydata);


}


Log.e("mylistmovie",mylistmovie.toString());
Log.e("mylistmovie",mylistmovie.size()+"");
} catch (JSONException e) {
e.printStackTrace();
}

Home_Adapter ma=new Home_Adapter(getActivity(), mylistmovie);
gv_mov.setAdapter(ma);

  hidepDialog();
}

Comments