-1

これは、このコードが実行することになっていることです。

ボタンを押すと、現在の画像が取得され、「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;

}

4

1 に答える 1

0

これを試して。

Drawable drawable = LoadImageFromWebOperations(ImageLink);
        imageView.setImageDrawable(drawable);


  private Drawable LoadImageFromWebOperations(String url)
    {
          try{


        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return d;
      }catch (Exception e) {
        System.out.println("Exc="+e);
        return null;
      }
    }
于 2012-07-13T12:12:07.933 に答える