我使用下面的代码设置ListView,数据和按钮设置正确,当我滚动时也没有数据重复的问题,但是当我滚动颜色设置为所有文本字段时,我该如何解决它?
private class EfficientAdapter extends BaseAdapter {
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
System.gc();
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.albumlist, null);
holder = new ViewHolder();
holder.albumName = (TextView) convertView.findViewById(R.id.albumDetails);
holder.delete=(Button)convertView.findViewById(R.id.deletealbum);
holder.share=(Button)convertView.findViewById(R.id.shareProject);
holder.preview=(Button)convertView.findViewById(R.id.prevProject);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.albumName.setText(albumData[position][0]);
if((albumData[position][2].length()==0)){
holder.albumName.setTextColor(Color.RED);
}
holder.delete.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
.....
});
holder.preview.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
......
}
});
holder.share.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
......
});
return convertView;
}
答案 0 :(得分:1)
holder.albumName.setTextColor(Color.BLACK); //or whatever the original color is
holder.albumName.setText(albumData[position][0]);
if((albumData[position][2].length()==0)){
holder.albumName.setTextColor(Color.RED);
}
在移动之前,您应首先重置视图的原始颜色。 Listview只回收其中的视图,因此您必须承担将其设置恢复正常的负担。