I am Trying to download an Image into an ImageView by using the Volley Library.
I inject the response of the Volley Library into the ImageView, but I am not getting the desired result.
Please check my code and suggest where I can make the changes to get the desired result.
public class MainActivity extends AppCompatActivity {
Button response_click;
TextView text_response;
RequestQueue requestQueue;
ImageView image_download;
String server_url="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Starburst_in_NGC_4449_(captured_by_the_Hubble_Space_Telescope).jpg/1024px-Starburst_in_NGC_4449_(captured_by_the_Hubble_Space_Telescope).jpg";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
response_click=(Button) findViewById(R.id.click_response);
text_response=(TextView) findViewById(R.id.text_response);
image_download=(ImageView)findViewById(R.id.image_download);
}
public void response_click(View view){
requestQueue= Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest=new StringRequest(Request.Method.POST, server_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
image_download.setImageResource(Integer.parseInt(response));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
text_response.setText("ou got an error...");
}
});
}
}