2012-09-11 75 views

回答

0

我們必須在使用更多圖像時使用lazyloading概念。如果這是你想要看看http://androidsnips.blogspot.in/2010/08/lazy-loading-of-images-in-list-view-in.htmlhttp://thinkandroid.wordpress.com/2012/06/13/lazy-loading-images-from-urls-to-listviews/ 當使用這個概念時,第一次加載的圖像被存儲在內存中,如果再次獲得相同的圖像,它將被直接檢查並顯示,而不會再次加載。 希望這是你需要的

+0

這不是懶惰的加載問題。這僅僅是獲得2000張以上圖像中大約10個畫廊的列表。 –

+0

我正在尋找更好的查詢。一些不是訂單N. –

+0

以及甚至我也在尋找更好的解決方案。 –

2

下面的解決方案是爲我工作。我發現在預測中做出明顯不是媒體內容提供商的選擇。此外,這似乎與cursorLoader一起使用。

 // TODO Auto-generated method stub 
    String[] projection = { Images.Media._ID, Images.Media.BUCKET_DISPLAY_NAME }; 

    HashMap<String, String> imagesGroups = new HashMap<String, String>(); 
    String ids = null; 

    Cursor c = _myContext.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null); 
    if (c.getCount() > 0) 
    { 
     c.moveToFirst(); 
     do 
     { 
      String bucketDisplayName = c.getString(c.getColumnIndex(Images.Media.BUCKET_DISPLAY_NAME)); 
      String _id = c.getString(c.getColumnIndex(Images.Media._ID)); 

      //here is where we ensure we get a unique image id for each distinct bucket display name 
      if(!imagesGroups.containsKey(bucketDisplayName)) 
      { 
       imagesGroups.put(bucketDisplayName, _id); 

       if(ids == null) 
        ids = _id; 
       else 
        ids += "," + _id; 
      } 
     } 
     while (c.moveToNext()); 
    } 

    c.close(); 

    String selection = Images.Media._ID + " IN (" + ids + ")"; 

    CursorLoader cursorLoader = new CursorLoader(this, Images.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null); 
    return cursorLoader;