目前,我有一个自定义列表适配器,它有一些逻辑可以根据变量隐藏/显示某个ImageView。
最初,逻辑在应用首次启动时有效。 (相应地隐藏/显示ImageView。)
但是一旦我上下滚动屏幕,最终所有行的ImageView都会永远隐藏。
有谁知道如何解决这个问题?
这是我的适配器:
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
PostHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new PostHolder();
holder.postThumb = (ImageView)row.findViewById(R.id.post_Thumb);
holder.postComments = (TextView)row.findViewById(R.id.post_comments);
holder.postInfo = (TextView)row.findViewById(R.id.item_subtitle);
holder.postScore = (TextView)row.findViewById(R.id.post_score);
holder.postTitle = (TextView)row.findViewById(R.id.item_title);
holder.postThumbHolder = (LinearLayout)row.findViewById(R.id.post_Thumb_holder);
row.setTag(holder);
}
else
{
holder = (PostHolder)row.getTag();
}
HashMap<String, String> post = data.get(position);
if(post.get("thumbnail").equals("default") || post.get("thumbnail").equals("self")){
holder.postThumbHolder.setVisibility(View.GONE);
}
holder.postComments.setText(post.get("comments"));
holder.postInfo.setText(post.get("info"));
holder.postScore.setText(post.get("score"));
holder.postTitle.setText(post.get("title"));
return row;
}
static class PostHolder
{
LinearLayout postThumbHolder;
ImageView postThumb;
TextView postComments;
TextView postScore;
TextView postTitle;
TextView postInfo;
}
答案 0 :(得分:2)
它与android如何在开始滚动时将列表项的背景设置为位图有关。为确保滚动后图像视图可见,每次调用适配器getView时都必须设置该属性在变量检查的else部分执行此操作
if(post.get("thumbnail").equals("default") || post.get("thumbnail").equals("self")){
holder.postThumbHolder.setVisibility(View.GONE);
} else {
holder.postThumbHolder.setVisibility(View.VISIBLE);
}
答案 1 :(得分:0)
在某处将可见性View.VISIBLE
设置为postThumbHolder
。在你的else块中
if (post.get...
子句。