2015-12-07 84 views
-1

我在使用convertview的listview上使用ArrayAdapter。但是當它滾動時,有一些項目重複。你能幫我解決問題嗎? getView功能的感謝 主要代碼:滾動時重複的列表視圖項目

 View view; 
     if (null != convertView) { 
      view = convertView; 
     } else { 
      view = getActivity().getLayoutInflater().inflate(R.layout.item_fans_task, null); 
      taskImg = (ImageView) view.findViewById(R.id.task_img); 
      taskTitleText = (TextView) view.findViewById(R.id.task_title_text); 
      taskContentText = (TextView) view.findViewById(R.id.task_content_text); 
      taskProcessImg = (ImageView) view.findViewById(R.id.task_process_img); 
      shareText = (TextView) view.findViewById(R.id.share_text); 
      taskType = (TextView) view.findViewById(R.id.task_type); 
     } 
     Tasks task = getItem(position); 

     taskTitleText.setText(task.getTitle()); 
     StringBuilder builder = new StringBuilder(); 
     builder.append("已將文章分享到朋友圈,並獲得" + task.getReaders() +"次閱讀\n"); 
     builder.append("已分享" + task.getTsum() + "次" + " 剩餘" + task.getSynum() + "次"); 
     taskContentText.setText(builder); 

...

 return view; 
+0

也分享您的適配器代碼。 – dex

+0

可能重複http://stackoverflow.com/questions/8261376/duplicated-entries-in-listview – DGN

回答

1

你分配你的 「UI」 開頭的變量,只有當不存在以回收(查看== NULL)。 也許應該使用ViewHolder模式。就目前而言,下面應該確定:

View view; 
    if (null != convertView) { 
     view = convertView; 
    } else { 
     view = getActivity().getLayoutInflater().inflate(R.layout.item_fans_task, null); 
    } 
    taskImg = (ImageView) view.findViewById(R.id.task_img); 
    taskTitleText = (TextView) view.findViewById(R.id.task_title_text); 
    taskContentText = (TextView) view.findViewById(R.id.task_content_text); 
    taskProcessImg = (ImageView) view.findViewById(R.id.task_process_img); 
    shareText = (TextView) view.findViewById(R.id.share_text); 
    taskType = (TextView) view.findViewById(R.id.task_type); 
+0

它的工作原理,感謝您的幫助! –

相關問題