title: Android: How to redraw a graphic element?
body: <p>I have created a class RoundIcon which extends View and the class contains setIconImage() method:</p>
  
  <pre><code>public void setIconImage(int imageFromResources) {
      iconImage = BitmapFactory.decodeResource(getResources(), imageFromResources);
      iconWidth = iconImage.getWidth();
      iconHeight = iconImage.getHeight();
      refreshDrawableState();
  }
  </code></pre>
  
  <p>and there is a method onDraw():</p>
  
  <pre><code>@Override
  protected void onDraw(Canvas canvas) {
  
      if(px == 0 || py == 0)
      {
          px = 50;
          py = 50;
      }
  
  
      canvas.drawCircle(px, py, circleRadius, circlePaint);
      canvas.save();
  
      if(iconImage != null)
      {
          int cardinalX = px - iconWidth/2;
          int cardinalY = py - iconHeight/2;
          canvas.drawBitmap(iconImage, cardinalX, cardinalY, iconPaint);
      }
  
      canvas.restore();
  }
  </code></pre>
  
  <p>The problem is that the function onDraw() doesn't execute each time the method setIconImage() is called from main activity and therefore the icon doesn't change in the user interface.</p>
  
  <p>Does anyone know how to modify the code in order to redraw an image every time the method setIconImage is called?</p>