Android 我的customarayadapter似乎传递了错误的var
我正在使用customArrayAdapter在gridview中显示我的图片。当我打开“活动”时,一切都进行得很顺利,但当我向下滚动并向上滚动时,它会显示某些项目的三角形,而该id的pictureCorrect为1(我在DDMS中检查了我的数据库以确保)。它似乎总是发生在相同的项目上。。。这是我的自定义适配器的一部分:Android 我的customarayadapter似乎传递了错误的var,android,gridview,adapter,Android,Gridview,Adapter,我正在使用customArrayAdapter在gridview中显示我的图片。当我打开“活动”时,一切都进行得很顺利,但当我向下滚动并向上滚动时,它会显示某些项目的三角形,而该id的pictureCorrect为1(我在DDMS中检查了我的数据库以确保)。它似乎总是发生在相同的项目上。。。这是我的自定义适配器的一部分: if (mView == null) { LayoutInflater vi = (LayoutInflater) getContext().getS
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;
}
你知道这是什么原因吗 由于视图循环,您需要在所有可能的情况下设置三角形的内容 在这里,如果correctPicture==1,则三角形图像资源是以前的任何内容,可能是三角化的
if (correctPicture == 1) {
triangle.setVisibility(View.VISIBLE);
// Add whatever initial value it is
triangle.setImageResource(R.drawable.initvalue);
}
我也经历过同样的事情,但还没有找到一个好的解决办法。这感觉就像listview中的一个小错误,关于处理图像所引入的延迟。啊,我明白了,这听起来很合乎逻辑。这就成功了,哇哈:谢谢,我已经找了一段时间了!