我有一個列表中顯示的圖像的所有URI的數組。 現在我想在後臺運行一個線程,從web獲取這些圖像並將它們存儲在SD卡上。 所以,當我點擊列表中的某個元素而不是從網頁抓取時,它應該從新的活動中從SD卡中獲取。在顯示列表視圖的同時下載圖像
我該怎麼做?
我有一個列表中顯示的圖像的所有URI的數組。 現在我想在後臺運行一個線程,從web獲取這些圖像並將它們存儲在SD卡上。 所以,當我點擊列表中的某個元素而不是從網頁抓取時,它應該從新的活動中從SD卡中獲取。在顯示列表視圖的同時下載圖像
我該怎麼做?
檢查WebImageView matthiaskäppler。
你可以用你想要的SDcard功能代替他緩存圖像的方式。
使用AsyncTask在後臺下載,同時顯示你的UI
File imageFile;
保存從網頁圖片
public View getView(int position, View convertView, ViewGroup parent) {
imageFile = new File("/sdcard/jorgesysTemp/" + Arraypicname(position);
if(!imageFile.exists()){
AsyncTaskProcess() //Download your images to sdcard
}
當您點擊列表視圖從SD卡加載圖像
@Override
protected void onListItemClick(ListView l, View v, final int position, long id) {
//load from sdcard
Bitmap bitmapImg = BitmapFactory.decodeFile("/sdcard/jorgesysTemp/" + Arraypicname(position));
BitmapDrawable drawableImg = new BitmapDrawable(bitmapImg);
myimageview.setImageDrawable(drawableImg);
...
...
...
你可能嘗試使用我的lazy-drawa統計局框架(GPL V3行貨):
https://github.com/rtyley/lazy-drawables
-unfortunately它不是完全準備好生產還沒有,但其中的東西它試圖處理:
......一旦你有一個懶惰的抽拉會話建立,填充的形象圖一樣簡單:
Drawable avatarDrawable = imageSession.get(someUserIdentifier); // doesn't block
imageView.setImageDrawable(avatarDrawable);
你不「T 護理它可能立即返回你一個正常的bitmapdrawable,或可能催生一個異步任務,並返回一個佔位符繪製 - 提拉將更新本身和它的主機的ImageView當異步任務已經完成。
無論如何這就是理論。這似乎八九不離十,有點工作至今,但有時自發UI更新不會發生......不知道爲什麼: - }
閱讀本線,有很多的信息。 http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview 我更喜歡Android系統的通用 - 圖片 - 裝載機庫的https:/ /github.com/nostra13/Android-Universal-Image-Loader,但您也可以找到其他解決方案。希望能幫助到你。 – 2012-08-10 12:08:52