onDraw(...) method not called after invalidate() for class extending ImageView

  • Replies:0
Rookatu
  • Forum posts: 1

Jul 23, 2013, 6:59:18 AM via Website

Hello! This is my first post on this site.

I've got a class LayeredImageView extending ImageView which I use to layer bitmaps on top of each other as needed. I have overridden the onDraw(...) method, but whenever I call either setImageBitmap(...) or invalidate() on an instance of the class, the onDraw(...) method is not called. I verified this using appropriately placed Log.d(...) statements.

I have also tried calling postInvalidate() rather than invalidate(), and had no luck there either. Also, my instance of the class is not null, which I verify by printing statements to the logcat from other methods of the class.

The call to setImageBitmap(...) is coming from a class extending BaseAdapter which I use to house my LayeredImageView's. Here is the relevant code:

1public View getView(int position, View convertView, ViewGroup parent) {
2 LayeredImageView imageView;
3 if (convertView == null) { // if it's not recycled, initialize some attributes
4 imageView = new LayeredImageView(mContext);
5 //imageView.setLayoutParams(new LayoutParams(85, 85));
6 imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
7 imageView.setPadding(7, 5, 7, 5);
8 }
9 else{
10 imageView = (LayeredImageView) convertView;
11 }
12
13 Piece piece = game.getPiece(position % 10, 9-position/10);
14 if(piece != null){
15 imageView.setHealth(piece.getHealth());
16 }
17
18 imageView.setImageBitmap(mThumbIds[position]);
19 imageView.invalidate();
20 //imageView.postInvalidate();
21
22 return imageView;
23 }

Here mThumbIds is an array of Bitmaps. So, any idea why onDraw is not getting called?
Thanks very much!

Reply