我有一个 customArrayAdapter 在我的 gridview 中显示我的图片。当我打开活动时,一切顺利,但是当我向下滚动和备份时,它显示一些项目的三角形红色,而该 ID 的图片正确为 1(我在 DDMS 中检查了我的数据库以确保)。它似乎一直在发生相同的项目......这是我的自定义适配器的一部分:
if (mView == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mView = vi.inflate(R.layout.caa_xml, null);
}
ImageView image = (ImageView) mView.findViewById(R.id.iv_caarow);
ImageView triangle = (ImageView) mView.findViewById(R.id.iv_triangle);
image.setAlpha(255);
triangle.setVisibility(View.INVISIBLE);
//… some additional code to define resizedBitmap
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
image.setImageDrawable(bmd);
if (mView != null) {
Picture pictureGiven = null;
loadDataBase();
pictureGiven = myDbHelper.getPictureGiven(getItem(position).getId(),
player);
int attempts = pictureGiven.getAttempts();
int correctPicture = pictureGiven.getPictureCorrect(); //returns 0 or 1
triangle.setVisibility(View.INVISIBLE);
if (correctPicture == 1) {
triangle.setVisibility(View.VISIBLE);
}
if (correctPicture != 1 && attempts > 0) {
triangle.setVisibility(View.VISIBLE);
triangle.setImageResource(R.drawable.trianglered);
}
}
return mView;
}
有什么想法可能导致这种情况吗?