Good day, I have some problem with my GridView.
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
if(LevelActivity.comp[position] == 1)
{
imageView.setBackgroundResource(R.drawable.back_got);
Bitmap btm;
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
btm = drawable.getBitmap();
btm = convertColorIntoBlackAndWhiteImage(btm);
imageView.setImageBitmap(btm);
}
return imageView;
}
Here’s code of my ImageAdapter, which set images in GridView. And if position of element is same to position in array with value of 1, it sets b&w image with special background instead of normal image. Everything works fine, BUT:
when I scroll my GridView, that special b&w images starts to “share” their backgrounds to images on their right. So after scrolling I get normal image with special background beside every special b&w element.
Hope you got an idea, thanks.
Image with problem: https://i.stack.imgur.com/Hbtwg.png
Ok, I’ve got an answer. It is really similar to random-items-in-GridView problem. So all I’ve need to do is set background bitmap directly on canvas (inside b&w function).