This is what this piece of code is supposed to do.
When the button is pressed, it is supposed to take the current image, and replace it with the one in the url that is in the string “finalurl”
What it does
It takes the current image and just makes it dissappear. It does not replace with any other image. Ive been stuck on this for a few days and im stumped. Any help is appreciated.
Here is the code i used.
public void firstbutton(View view)
{
Context context = view.getContext();
Drawable image = ImageOperations(context, "@string/finalurl","image.jpg");
ImageView icon = new ImageView(context);
icon = (ImageView)findViewById(R.id.imageView);
icon.setImageDrawable(image);
};
private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
Try This.