0

我在Android上的列表視圖中滾動圖像(延遲加載)上傳重複前兩個。 照片是從一個在線服務器上傳 另外,在Android 4.4上,照片非常大。 爲什麼?解決方案?從列表中的服務器重複列表視圖圖像

@Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder holder; 

     Log.d(TAG, "POS: " + position);   

     if (convertView == null) { 

      convertView = mLayoutInflater.inflate(R.layout.row_posts, parent, false); 

      holder = new ViewHolder(); 
      holder.tvTitolo = (TextView) convertView.findViewById(R.id.tvTitoloPost); 
      holder.tvData = (TextView) convertView.findViewById(R.id.tvData); 
      holder.ivPost = (ImageView) convertView.findViewById(R.id.ivPost); 
      holder.tvContent = (TextView) convertView.findViewById(R.id.tvContent); 
      holder.tvExcerpt = (TextView) convertView.findViewById(R.id.tvExcerpt); 
      holder.wvPost = (WebView) convertView.findViewById(R.id.wvPost); 
      holder.tvIDPost = (TextView) convertView.findViewById(R.id.tvIDPost); 
      holder.tvUrlPost = (TextView)convertView.findViewById(R.id.tvURLPost); 
      holder.tvCommPost = (TextView)convertView.findViewById(R.id.tvCommPost); 
      convertView.setTag(holder);    
     }else { 
      holder = (ViewHolder) convertView.getTag(); 
     }final Post post = getItem(position);    
     holder.tvTitolo.setText(post.getTitle()); 
     holder.tvData.setText(post.getDate());  
     WebSettings webSettings = holder.wvPost.getSettings(); 
     webSettings.setBuiltInZoomControls(false); 
     webSettings.setUseWideViewPort(true); 
     webSettings.setJavaScriptEnabled(true); 
     webSettings.setSupportMultipleWindows(true); 
     webSettings.setJavaScriptCanOpenWindowsAutomatically(true); 
     webSettings.setLoadsImagesAutomatically(true); 
     webSettings.setLightTouchEnabled(true); 
     webSettings.setDomStorageEnabled(true); 
     webSettings.setLoadWithOverviewMode(true); 
     holder.wvPost.setFocusable(false); 
     holder.wvPost.setClickable(false); 
     holder.wvPost.setFocusableInTouchMode(false); 
     holder.wvPost.setLongClickable(false); 
holder.wvPost.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); 
     holder.wvPost.loadUrl(post.getThumbnail()); 
     Log.v(TAG, "html: <!DOCTYPE html><html><body style = \"text-align:center\"><img src= " + post.getThumbnail() + " alt=\"\"></body></html>"); 
     holder.wvPost.loadDataWithBaseURL(null,"<!DOCTYPE html><html><body style = \"text-align:center\"><img src= " + post.getThumbnail() + " alt=\"\"></body></html>","text/html", "UTF-8", null); 
     holder.wvPost.setClickable(false); 

    if (post.getThumbnail().equals("null")) { 
      imageLoader.displayImage(null, holder.ivPost); 
     }else { 
      imageLoader.displayImage(post.getThumbnail(), holder.ivPost); 
     }   
     Log.d(TAG, "THUMB: " + post.getThumbnail());    
     /* if(post.getThumbnail().equals("null")){ 
      holder.ivPost.setVisibility(View.GONE); 
     }else{ 
      imageLoader.displayImage(post.getThumbnail(), holder.ivPost); 
      holder.ivPost.setVisibility(View.VISIBLE);   
     }*/ 

     imageLoader.displayImage(post.getThumbnail(), holder.ivPost); 

     holder.tvExcerpt.setText(post.getExcerpt()); 
     holder.tvContent.setText(post.getContent()); 
     holder.tvIDPost.setText(post.getId()); 
     holder.tvUrlPost.setText(post.getThumbnail()); 

     String comments = ""; 

     for (int i = 0; i < post.getmComments().size(); i++) { 
      comments = "<b>" + post.getmComments().get(i).getName() + 
         "</b><br>" + 
         post.getmComments().get(i).getContent() + 
         "<br><b>on </b>" + 
         post.getmComments().get(i).getDate() + 
         "<br><br>"; 
     }   
     holder.tvCommPost.setText(comments);       
     return convertView; 
    }} 

XML row_post:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="10dp" 
    android:background="#ffffff" > 

    <TextView 
     android:id="@+id/tvTitoloPost" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" 
     android:text="Titolo" 
     android:textSize="20sp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/tvData" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/tvTitoloPost" 
     android:layout_below="@+id/tvTitoloPost" 
     android:text="Data" /> 

    <WebView 
     android:id="@+id/wvPost" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tvData" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" 
     android:background="#ffffff" 

      /> 

    <ImageView 
     android:id="@+id/ivPost" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tvData" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" 
     android:src="@drawable/default_avatar" 
     android:visibility="gone" /> 

    <TextView 
     android:id="@+id/tvExcerpt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/wvPost" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="15dp" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/tvContent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/wvPost" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="15dp" 
     android:maxLines="4" 
     android:text="TextView" 
     android:visibility="gone" /> 

    <TextView 
     android:id="@+id/tvIDPost" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/tvContent" 
     android:layout_below="@+id/tvContent" 
     android:text="TextView" 
     android:visibility="gone" /> 

    <TextView 
     android:id="@+id/tvURLPost" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/tvIDPost" 
     android:layout_below="@+id/tvContent" 
     android:text="TextView" 
     android:visibility="gone" /> 

    <TextView 
     android:id="@+id/tvCommPost" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/tvURLPost" 
     android:layout_below="@+id/tvContent" 
     android:text="TextView" 
     android:visibility="gone" /> 

</RelativeLayout> 
+0

分享R.layout.row_posts。 –

+0

row_post.xml已上架 – DevOkAnd

回答

0

也許你已經緩存圖像。使用應用程序管理器刪除數據並再次啓動。

編輯:請確保您撥打只是一次displayImage方法內getView:使用

Evoid比較與空與等號:

if (post.getThumbnail().equals("null")) 

相反,使用方法如下:

if (!TextUtils.isEmpty(post.getThumbnail()))  

最後:

//!TextUtils.isEmpty performs 2 checks: 1) Object!=null 2) Is not an empty String 
if (!TextUtils.isEmpty(post.getThumbnail())) { 
    imageLoader.displayImage(post.getThumbnail(), holder.ivPost); 
} 
// No more callings to displayImage!! 
+0

不,我試過了! – DevOkAnd

+0

好吧,然後刪除superflous代碼: imageLoader.displayImage(post.getThumbnail(),holder.ivPost); 對於getview的每個實例,您總是調用兩次。之後檢查日誌: Log.d(TAG,「THUMB:」+ post.getThumbnail()); 檢查URL是否重複或不是每個位置。另外,請發表你的getItem(位置)代碼 – Billyjoker

+0

我在else裏面評論了代碼,情況有所改善。然而,在幾納秒內拍攝更多照片,而不是很快上傳。 我不明白我應該發佈什麼? – DevOkAnd