2014-09-26 55 views
0

所以問題是 1.我們正在使用listView的聊天應用程序 2。每次發送聊天或rec時,我們都會更新arrayList並更新適配器,並執行notifydatasetAdaper()以刷新列表視圖。 3.因此,如果我們在聊天中發送10個圖像,然後發送第11個聊天信息(比如說文字chtat),然後調用notifydatasetadapter(),則在這種情況下,所有10個圖像都會刷新。 4.所以我需要停止刷新圖像。 5. ListView必須刷新,而不刷新圖像對話listview停止刷新圖像視圖

所以任何想法我怎麼能實現這個..或者可能在錯誤的路徑m請告訴我正確的做法..... !!!

我也嘗試過使用picaso,但庫與okhttp庫衝突.... !!!

而且我這是在展示這些圖像

public class ImageFromSd extends AsyncTask<Object, Bitmap, Bitmap> { 

     ImageView im; 

     // int targetWidth = 200; 
     // int targetHeight = 200; 

     @Override 
     protected Bitmap doInBackground(Object... params) { 
      // TODO Auto-generated method stub 
      Bitmap bitmap = null; 
      try { 
       im = (ImageView) params[0]; 
       String path = (String) im.getTag(); 

       Log.d("ankit", "image path :::::" + path); 
       bitmap = BitmapFactory.decodeFile(path); 

       // bitmap.compress(CompressFormat.JPEG, 100, new 
       // FileOutputStream(
       // path)); 
       // 
       // bitmap = Bitmap.createScaledBitmap(bitmap, targetWidth, 
       // targetHeight, false); 
      } 
      // catch (FileNotFoundException e) { 
      // e.printStackTrace(); 
      // bitmap = null; 
      // } 
      catch (OutOfMemoryError e) { 
       e.printStackTrace(); 
       bitmap = null; 
      } catch (NullPointerException e) { 
       e.printStackTrace(); 
       bitmap = null; 
      } catch (Exception e) { 
       e.printStackTrace(); 
       bitmap = null; 
      } 

      return bitmap; 
     } 

     @Override 
     protected void onPostExecute(Bitmap result) { 
      // TODO Auto-generated method stub 
      super.onPostExecute(result); 

      if (result != null) { 
       im.setScaleType(ScaleType.FIT_CENTER); 
       im.setImageBitmap(result); 

      } 
     } 

    } 


and then calling it like this 
    im.setTag(items.get(i).getTextChat()); 
    new ImageFromSd().execute(im); 
+0

請張貼代碼列表視圖和適配器 – AndroidEnthusiast 2014-09-26 14:30:17

回答

0

首先,你必須刷新列表視圖列表視圖作爲內的任何數據更新的方式。

Secondly, the method you using for loading image is not good. 

try this library to load remote or local image. it maintains cache automatically and very efficient for image loading. 

通用圖像裝載機
https://github.com/nostra13/Android-Universal-Image-Loader

+0

jatin我刷新從loacal SD卡我的事情GCM味精正在添加和加載圖像列表視圖UIL不會幫我從本地SD卡加載圖像 – shankey 2014-09-26 14:36:14

+0

是的,你也可以使用這個庫加載你的SD卡圖像。 – Jatin 2014-09-26 14:39:18

+0

你只需要傳遞路徑,不需要做位圖,這會節省你的內存 – Jatin 2014-09-26 14:39:46