1

我的問題是我已經實現了一個自定義的arrayadapter,它從url中獲取圖像並將它們設置爲imageview。它的工作,有點。有時候某些圖像沒有顯示出來。有時候這只是一張圖片,有時是三張,沒有明顯的順序。唯一合理一致的是,它似乎是我的數據列表中的圖像編號3。有時我的圖標在我的列表視圖中沒有顯示

我的自定義適配器:

public CustomAdapter(Context context, int textViewResourceId, List items) 
{ 
     super(context, textViewResourceId, items); 
     this.items = items; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) 
{ 
    View v = convertView; 
    if (v == null) 
    { 
     LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = vi.inflate(R.layout.list_item, parent, false); 
    } 
    Object o = items.get(position); 
    if (o != null) 
    { 
      TextView textView = (TextView) v.findViewById(R.id.listItem); 
      ImageView imageView = (ImageView) v.findViewById(R.id.icon); 

      if (textView != null) 
      { 
       textView.setText(o.toString()); 
      } 
      if (imageView != null) 
      { 
       if (o instanceof XmlGuide) 
       { 
        try 
        { 
         imageView.setImageBitmap(downloadIcon(((XmlGuide) o).getIcon())); 
        } 
        catch(Exception e) 
        { 
         e.printStackTrace(); 
        } 
       } 
      } 
    } 
    return v; 
} 

private Bitmap downloadIcon(String uri) throws Exception 
{ 
    URL url = new URL(uri); 
    InputStream stream = url.openStream(); 
    Bitmap icon = BitmapFactory.decodeStream(stream); 
    stream.close(); 
    return icon; 
} 

回答

0

我終於明白了這個問題。問題是,Android的< 2.3沒有很好地處理JPG圖像。有一個修復程序,它將在大多數情況下解決這個問題,但不是全部。

你可以閱讀更多關於它在這裏:http://code.google.com/p/android/issues/detail?id=6066

0

有你的getView期間阻塞網絡部分不建議報告。

使用

setImageUri(Uri.parse(o.getIcon()); 

肯定是更好。

+0

我調用getIcon()返回一個字符串,它並沒有真正與setImageUri –

+0

這就是爲什麼我寫了「Uri.parse工作這麼好(o.getIcon()) 「 – njzk2

相關問題