2011-09-10 7 views
2

を働いていない:ImageViewの持つカスタムビューを作成し、Asynctask私はViewFlipperにプログラムでビューを追加したい

public View anEpisode(String n, String i, String d){ 
    View v; 
    LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    v = inflater.inflate(R.layout.episodedescription, null); 

    TextView nameOfEpisode = (TextView) v.findViewById(R.id.episodedescriptionname); 
    ImageView imageOfEpisode = (ImageView) v.findViewById(R.id.episodedescriptionimage); 
    TextView descriptionOfEpisode = (TextView) v.findViewById(R.id.episodedescriptiondescription); 

    nameOfEpisode.setText(n); 
    descriptionOfEpisode.setText(d); 
    createUrlImage(imageOfEpisode, i); 

    return v; 
} 

とcreateUrlImageは次のとおりです:

flipper.addView(anEpisode(name, null, description), i); 

私の方法がある

private class CreateImage extends AsyncTask<String, Void, Drawable> { 
    ImageView image; 
    public CreateImage(ImageView img) { 
     image = img; 
    } 
    protected void onPreExecute() { 
    } 

    protected Drawable doInBackground(String... urls) { 
     InputStream is; 
     Drawable d = null ; 
     try { 
      is = (InputStream)new URL(urls[0]).getContent(); 
      d = Drawable.createFromStream(is, "Image"); 
      return d; 
     } catch (MalformedURLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     return d; 
    } 
    protected void onPostExecute(Drawable d) { 
     image.setBackgroundDrawable(d); 
    } 
} 
public void createUrlImage(ImageView img, String url){ 
    new CreateImage(img).execute(url); 
} 

事は:画像を全く表示しないので、私は何をすべきかわかりません。

+0

あなたのコードをトレースして、コンピュータが何をするかを確認できます。 – Snicolas

+0

どうすればいいですか?私はデバッガの使い方を知っています。 – Tsunaze

+0

ResourceType:リソースにはリソース番号0x7fのパッケージは含まれていません....すべてのページにこの行があります。 – Tsunaze

答えて

0

問題は描画可能な境界であると思います。 onPostExecute()メソッドで範囲を設定します。

protected void onPostExecute(Drawable d) { 
    d.setBounds (0, 0, getIntrinsicWidth(), getIntrinsicHeight()); 
    image.setBackgroundDrawable(d); 
} 
+0

getIntrinsicWidthとgetIntrinsicHeightは何ですか? – Tsunaze

+0

おかげで、それはdrawableからのメソッドでしたが、うまくいかず、アプリケーションが遅くなりました。 – Tsunaze

+0

はい、drawableのメソッドです。それを逃した。 'getIntrinsicWidth'と' getIntrinsicHeight'の代わりに静的な値を与えてみてください。 'd.setBounds(0、0、100、100);'のように、あるいは本当の高さと幅を超えないと思われるものは何ですか? – Ronnie

関連する問題