滚动列表时,列表中的项目变得混乱。 我正在使用基本适配器进行自定义列表。
我的代码是:
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();
}
答案 0 :(得分: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;
}
并使用
查看持有人