我有一个自定义列表视图,其中有一个 Textview 和 Imageview 现在我想隐藏或显示 Listview 中某些项目的 Imageview。
我已经使用 getview 方法完成了此操作,但问题是当第一次显示 Listview 时,视图不会隐藏,但是当我向下滚动并向上滚动时,它会被隐藏。以下是代码片段。提前致谢。
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
ViewHolder holder;
if (v != convertView && v != null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.jazzartist, null);
holder.albumsView = (TextView)convertView.findViewById(R.id.artist_albums_textview);
v.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag(); }
ViewHolder holder1 = (ViewHolder) v.getTag();
holder1.objimg = (ImageView)convertView.findViewById(R.id.drag);
if(position == 4){
(holder1.objimg).setVisibility(View.INVISIBLE); // here I am hiding Imageview for position 4
}
else
{
(holder1.objimg).setVisibility(View.VISIBLE); // here I am showing Imageview for rest of items
}
String albums = getItem(position).albums;
holder1.albumsView.setText(albums);
return v;
}
}
}