我使用這個技術,Android版來取得照片桶或畫廊名單獲取圖像畫廊名單是太慢了 - 我需要快速BUCKET_DISPLAY_NAME查詢
Get list of photo galleries on Android
然而,這迭代通過每幅圖像並且對於超過1000張圖像很慢。
有沒有辦法使用SQL(也許DISTINCT關鍵字?)來更快地獲取BUCKET_DISPLAY_NAMEs的列表?
我使用這個技術,Android版來取得照片桶或畫廊名單獲取圖像畫廊名單是太慢了 - 我需要快速BUCKET_DISPLAY_NAME查詢
Get list of photo galleries on Android
然而,這迭代通過每幅圖像並且對於超過1000張圖像很慢。
有沒有辦法使用SQL(也許DISTINCT關鍵字?)來更快地獲取BUCKET_DISPLAY_NAMEs的列表?
我們必須在使用更多圖像時使用lazyloading概念。如果這是你想要看看http://androidsnips.blogspot.in/2010/08/lazy-loading-of-images-in-list-view-in.html或http://thinkandroid.wordpress.com/2012/06/13/lazy-loading-images-from-urls-to-listviews/ 當使用這個概念時,第一次加載的圖像被存儲在內存中,如果再次獲得相同的圖像,它將被直接檢查並顯示,而不會再次加載。 希望這是你需要的
下面的解決方案是爲我工作。我發現在預測中做出明顯不是媒體內容提供商的選擇。此外,這似乎與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;
這不是懶惰的加載問題。這僅僅是獲得2000張以上圖像中大約10個畫廊的列表。 –
我正在尋找更好的查詢。一些不是訂單N. –
以及甚至我也在尋找更好的解決方案。 –