2015-06-19 24 views
1

我正在在android系統的imageLoading演示不改變,我已經使用第一UniversalImageLoader然後picasso,然後一個ImageLoader類,但任何時候,當我上傳新的圖片到服務器,併成功上傳到服務器,並在我試圖將它設置爲ImageView,之前加載的圖像保持不變,它沒有變化,我非常沮喪並且浪費了2天來解決這個問題,因爲沒有運氣,請幫助我挽救我的生命。形象的ImageView

我的代碼如下:

Picasso.with(getApplicationContext()) 
      .load(Pref.getValue(getApplicationContext(), 
        Const.PREF_PROFILE_PIC, "")).into(iv_profile); 

    Picasso.with(getApplicationContext()) 
      .load(Pref.getValue(getApplicationContext(), 
        Const.PREF_COVER_PIC, "")).into(iv_cover); 
+0

Picasso,UniversalImageLoader或任何其他圖像加載庫正在使用圖像緩存來重新加載圖像。所以無論您需要更改新圖像的名稱還是清除圖像緩存以加載新圖像。 – Piyush

+0

http://stackoverflow.com/questions/11893826/how-to-refresh-image-view-immediately –

回答

3

嘗試在URL的末尾添加cachebreaker

String imageurl1 = Const.PREF_PROFILE_PIC + "?" + new Date().getTime(); 
String imageurl2 = Const.PREF_COVER_PIC + "?" + new Date().getTime(); 

Picasso.with(getApplicationContext()) 
     .load(Pref.getValue(getApplicationContext(), 
       imageurl1, "")).into(iv_profile); 

Picasso.with(getApplicationContext()) 
     .load(Pref.getValue(getApplicationContext(), 
       imageurl2, "")).into(iv_cover); 

這將自動追加當前的時間戳,當你正在創建的圖像,並它將使瀏覽器再次查找圖像,而不是檢索緩存中的一個。

+0

謝謝你neeraj您的答覆,但我從服務器獲取這個圖像的URL,所以我不能改變url.Any其他解決方案?請請.i將等待您的回覆 –

+0

不能修改imageurl? –

+0

噢,我的上帝......你是天才曼...... !!非常感謝,你救了我的一天...... Neeraj上帝保佑.. !!! –

0

這個想法和上面一樣。但它沒有爲我工作。

我得到了答案,從這個link

更改URL,如下圖所示:

String imageurl = url + "?time=" + System.currentTimeMillis(); 
Picasso.with(getContext()).load(imageurl).into(imageView); 

這爲我工作。謝謝