これは、このコードが実行することになっていることです。
ボタンを押すと、現在の画像が取得され、「finalurl」という文字列に含まれるURLの画像に置き換えられます。
それが何をするか
現在の画像を取得し、それを非表示にします。他の画像に置き換わるものではありません。私はこれに数日間立ち往生していて困惑しています。どんな助けでも大歓迎です。
これが私が使用したコードです。
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;
}