2016-05-11 99 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