2016-05-11 33 views
0

滾動列表時,列表中的項目變得混亂。 我正在使用自定義列表的基礎適配器。滾動列表時,列表中的項目變得混亂

我的代碼是:

public View getView(final int position, View convertView, ViewGroup parent) { 
    ViewHolder holder; 
    if (convertView == null) { 
     holder = new ViewHolder(); 
     convertView = View.inflate(context, R.layout.list_challenge_comp_cell, null); 
     holder.text_title = (TextView) convertView.findViewById(R.id.text_title); 
     holder.text_challenge = (TextView) convertView.findViewById(R.id.text_challenge); 
     holder.text_enroll_date = (TextView) convertView.findViewById(R.id.text_enroll_date); 
     holder.text_rewards = (TextView) convertView.findViewById(R.id.text_rewards); 
     holder.button_share = (Button) convertView.findViewById(R.id.button_enroll); 
     holder.progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar); 
     holder.layout_main = (LinearLayout)convertView.findViewById(R.id.layout_main); 
     holder.progressBar.setVisibility(View.VISIBLE); 
     holder.button_share.setText("Share"); 

     convertView.setTag(holder); 
    } else { 
     holder = (ViewHolder) convertView.getTag(); 
    } 
+1

請定義錯誤。此外,添加代碼的[最小,完整且可驗證的示例](http://stackoverflow.com/help/mcve)。 – Sevle

+0

發佈一些代碼到目前爲止您嘗試過的內容 –

+0

請發佈您的'Adapter'代碼。 –

回答

0

的代碼添加適配器,

@Override 
public int getViewTypeCount() { 
    // The total number of row types your adapter supports. 
    // This should NEVER change at runtime. 
    return VIEW_TYPE_COUNT; 
} 
@Override 
public int getItemViewType(int position) { 
    // return a value from zero to (viewTypeCount - 1) 
    if (position == 0) { 
     return VIEW_TYPE_HEADER; 
    } else if (position == getCount() - 1) { 
     return VIEW_TYPE_FOOTER; 
    } 
    return VIEW_TYPE_DEFAULT; 
} 

,並使用

查看持有者

Reference link