我有一个listview,我在其中显示文件和文件夹列表.我正在使用我的getView方法
static class ViewHolder {
protected TextView text1;
protected TextView text2;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row, parent, false);
viewHolder = new ViewHolder();
viewHolder.text1 = (TextView) convertView.findViewById(R.id.text1);
viewHolder.text2 = (TextView) convertView.findViewById(R.id.text2);
convertView.setTag(viewHolder);
}
else{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.text1.setText(itemsArrayList.get(position).getFileName());
viewHolder.text2.setText(itemsArrayList.get(position).getSize());
<if( itemsArrayList.get(position).isHidden() ) {
convertView.setBackgroundColor(context.getResources().getColor(R.color.hiddenColor));
}
return convertView;
}
Run Code Online (Sandbox Code Playgroud)
如果文件/文件夹被隐藏,我将列表项的背景颜色更改为hiddenColor,
(默认背景颜色为XML)
但在滚动时,它几乎将所有列表项背景颜色设置为hiddencolor.
我知道这是由于listview回收,但不知道如何解决它.
您还必须设置非隐藏颜色,因为如果重复使用该视图,如果在转换视图之前设置了hiddenColor,则会获得hiddenColor.
if( itemsArrayList.get(position).isHidden() ) {
convertView.setBackgroundColor(context.getResources().getColor(R.color.hiddenColor));
} else {
**convertView.setBackgroundColor(Put your other color here)**
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3295 次 |
| 最近记录: |