2010-12-02 89 views
1

全部 - 是否有人使用CursorAdapter與圖庫小部件?有大量的例子顯示Gallery和BaseAdapter(Array)作爲它的數據存儲。Android上的光標適配器和GalleryView

我的用例是從SQLite光標驅動圖庫。遊標具有要顯示的ImageURL。

我一直在其他ListView中使用DroidFu的ImageLoader(與一個ImageView)異步下載圖像。

但是,這似乎並沒有與畫廊合作。它(圖庫)不喜歡處理程序發回它。

因此... 對基於URL的圖像使用AsyncDownload的Gallery和Cursor適配器模式的任何想法?

感謝

回答

2

是的,但我用我自己的實現圖像加載器,非常類似於DroidFu的(在內存/文件緩存,螺紋和無螺紋圖像加載)。看起來你不能通過Gallery +光標適配器設置線程加載圖像,否則你會得到一個非常不連貫的滾動,而不是一個連續的平滑滾動。

這裏是一個示例代碼,我使用相同的遊標適配器的列表,畫廊和網格視圖。

public class CatalogCursorAdapter extends CursorAdapter { 

private Context context = null; 
private HLBitmapManager iMan; 
private CatalogViewHolder holder; 
private final LayoutInflater inflater; 
private int layout; 

public CatalogCursorAdapter(Context context, Cursor c, int layout) 
{ 
    super(context, c, true); 
    inflater = LayoutInflater.from(context); 
    this.layout = layout; 
    this.context = context; 
    iMan = new HLBitmapManager(context.getCacheDir()); 
} 

@Override 
public View newView(Context context, Cursor cursor, ViewGroup parent) { 
    final View view = inflater.inflate(layout, parent, false); 
      return view; 
} 

@Override 
public void bindView(View v, Context context, Cursor c) { 

    String brandName = c.getString(c.getColumnIndex("display_name")); 
    String category = c.getString(c.getColumnIndex("display_price")); 
    String imgUrl = c.getString(c.getColumnIndex("img_url")); 

    holder = (CatalogViewHolder) v.getTag(); 
    if(holder == null) { 
     holder = new CatalogViewHolder(v); 
     v.setTag(holder); 
    } 

    Bitmap image; 
    switch (this.layout) { 
    case R.layout.catalog_list_row: 
     holder.title.setText(brandName); 
     holder.sub_title.setText(category); 
     iMan.fetchBitmapOnThread(imgUrl, Constants.EVENT_LISTVIEW_IMG_WIDTH, Constants.EVENT_LISTVIEW_IMG_HEIGHT, holder.icon); 
     break; 
    case R.layout.catalog_grid_cell: 
     iMan.fetchBitmapOnThread(imgUrl, Constants.EVENT_LISTVIEW_IMG_WIDTH, Constants.EVENT_LISTVIEW_IMG_HEIGHT, holder.icon); 
     break; 
    case R.layout.catalog_slide_cell: 
     image = iMan.fetchBitmap(imgUrl, Constants.EVENT_LISTVIEW_IMG_WIDTH, Constants.EVENT_LISTVIEW_IMG_HEIGHT); 
     holder.icon.setImageBitmap(image); 
     break; 
    } 
    holder.icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 

} 
} 
+0

你能告訴我什麼是「HLBitmapManager」 – pengwang 2011-01-05 12:05:18

相關問題