title: Image could not be shown in canvas
body: <p>I am now working on a assignment that needs to make use of the Android studio to create an app with animation. However, I found that the image that I put on the drawable file could not be shown on the canvas. Therefore, I tried to added a line of <code>this.setWillNotDraw(false);</code> in order to show the image.
  Then I have to apply a click event to the app, and I found that it could not work.
  The code below is what I have now</p>
  <pre><code>public class Panel extends SurfaceView implements SurfaceHolder.Callback {
      private Bitmap bmp;
      private GameThread thread;
      private int x = 20;
      private int y = 20;
  
      public Panel(Context context) {
          super(context);
          bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
          thread = new GameThread(getHolder(), this);
          getHolder().addCallback(this);
          this.setWillNotDraw(false);
          setFocusable(true);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
          canvas.drawColor(Color.BLACK);
          canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, null);
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder holder) {
          thread.setRunning(true);
          thread.start();
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
  
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) {
          boolean retry = true;
          thread.setRunning(false);
          while (retry) {
              try {
                  thread.join();
                  retry = false;
              } catch (InterruptedException e) {
                  //keep trying here
              }
          }
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          x = (int) event.getX();
          y = (int) event.getY();
          return true;
      }
  }
  </code></pre>
  <p>And I also have two other java file within</p>
  <pre><code>public class GameThread extends Thread{
  
      private SurfaceHolder surfaceHolder;
      private Panel panel;
      private boolean run = false;
  
      public GameThread(SurfaceHolder surfaceHolder, Panel panel){
      this.surfaceHolder = surfaceHolder;
      this.panel = panel;
      }
  
      public void setRunning(boolean run){
          this.run = run;
      }
  
      @Override
      public void run() {
          super.run();
          Canvas c;
          while (run);
              c = null;
              try{
                  c = surfaceHolder.lockCanvas();
                  synchronized(surfaceHolder){
                      panel.onDraw(c);
                  }
              }finally{
                  if(c != null){
                      surfaceHolder.unlockCanvasAndPost(c);
                  }
              }
      }}
  
  
      public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(new Panel(this));
      }
  }
  </code></pre>
  <p>May I know what should I do to show the image and make use of the touch event at the same time?</p>