我正在使用 Facebook SDK 开发适用于 Android 的应用程序。到目前为止,该应用程序会扫描特定页面提要并将所有帖子放入 GridView。我想要这样,如果当前位置的 imageArray 的值为空或 null(没有图片的帖子),那么它将 ImageView 可见性设置为 GONE 并使 TextView 占据整个项目。这是我的代码:
public View getView(int position, View v, ViewGroup parent) {
MainListHolder mHolder;
if (v == null) {
mHolder = new MainListHolder();
v = inflator.inflate(R.layout.list_item, null);
mHolder.img1 = (ImageView) v.findViewById(R.id.preview);
mHolder.txt2 = (TextView) v.findViewById(R.id.message);
mHolder.txt3 = (TextView) v.findViewById(R.id.user_name);
mHolder.txt4 = (TextView) v.findViewById(R.id.user_id);
v.setTag(mHolder);
} else {
mHolder = (MainListHolder) v.getTag();
}
if (!imageArray.get(position).isEmpty()) {
manager.DisplayImage(imageArray.get(position), loader, mHolder.img1);
}
else {
manager.DisplayImage(null, loader, mHolder.img1);
mHolder.img1.setVisibility(ImageView.GONE);
}
mHolder.txt2.setText(messageArray.get(position));
mHolder.txt3.setText(nameArray.get(position));
mHolder.txt4.setText(idArray.get(position));
return v;
}
问题是 GridView 现在在我滚动时更改了它的项目。即使item有图片,ImageView也会消失。我该如何解决?