我有一个自定义列表适配器,我写了这段getView代码。 我面临的问题是,在滚动时,内容会混淆,图像会相互混合。
getView方法
public View getView(final int position, View convertView, ViewGroup parent) {
// if view not generated
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.post_list, null);
holder = new Holder();
holder.post_text=(TextView) convertView.findViewById(R.id.post_text);
holder.post_platform=(ImageView) convertView.findViewById(R.id.post_platform);
holder.post_image=(ImageView) convertView.findViewById(R.id.post_image);
convertView.setTag(holder);
} else {
holder= (Holder) convertView.getTag();
}
String network = getNetworkType(posts_platforms.get(position));
setHolderData(holder, network, position);
return convertView;
}
setHolderData方法
private void setHolderData(final Holder holder, String platform, final int position) {
holder.post_text.setText(posts_texts.get(position));
holder.post_platform.setImageResource(R.drawable.default_image);
holder. post_image.setImageResource(R.drawable.default_image);
}
知道我做错了吗?