2011-07-04 42 views
0

我想序列的默認懶列表代碼的HashMap並將其存儲在設備上的文件..機器人拯救懶列表的HashMap

其實我想在本地存儲的圖像,,,,

因爲我的項目包含很多從服務器使用的圖像....請提供修改後的lazy-list的方式或代碼,將Hash-Map存儲在文件中..下次重新啓動應用程序圖像加載器類必須具有該對象,以便不從服務器下載圖像...

回答

1

創建一個名爲cacheDir的變量並更改getBitmap()方法ImageLoader這個類下面的一個

private Bitmap getBitmap(String urlString) 
{ 
    String filename = String.valueOf(urlString.substring(urlString.lastIndexOf("/") + 1)); 
    File f = new File(cacheDir, filename); 
    try 
    { 
     if(!f.exists()) 
     { 
      Bitmap bitmap = null; 
      InputStream is = new URL(urlString).openStream(); 
      OutputStream os = new FileOutputStream(f); 
      Globals.CopyStream(is, os); 
      os.close(); 
      bitmap = decodeFile(f); 
      return bitmap; 
     } 
     else 
     {    
      Bitmap bitmap = decodeFile(f); 
      return bitmap; 
     } 

    } 
    catch (Exception ex) 
    { 
     ex.printStackTrace(); 
     BitmapDrawable mDrawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.placeholder); 
     return mDrawable.getBitmap(); 
    } 
} 
+0

Globals.CopyStream(is,os);在這Globals不能在代碼解決..這個代碼是有效的,當應用程序重新啓動我希望圖像被保存和使用,如果它們已經顯示在前面 –

+0

hiiii ,,, thx這是我的錯誤實現你的代碼,,,,現在正在工作...... –