title: Android studio SurfaceView onTouchEvent
body: <p>I have a SurfaceView in my activity xml and I want to get some informations when the SurfaceView is clicked. For that I have a class like below</p>
  <pre><code>class ImageTable extends SurfaceView implements SurfaceHolder.Callback {
  
   public ImageTable(Context context, SurfaceView surfaceView) {
          super(context);
  
          surfaceHolder =  surfaceView.getHolder();//getHolder();//
          surfaceHolder.addCallback(this);
          this.context = context;
          setFocusable(true);
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          Log.i(TAG,String.valueOf( event.getAction())+&quot;asd&quot;);
          switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                  
                  break;
              case MotionEvent.ACTION_MOVE:
                  
                  break;
  
              case MotionEvent.ACTION_UP:
  
                  break;
          }
      return true;
      }
  }
  
  
  </code></pre>
  <p>my activity is</p>
  <pre><code>
  public class SubmitActivity extends AppCompatActivity {
  
  SurfaceView test;
  
  protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_submit);
          test = findViewById(R.id.cylindersImage);
          context = this;
  
          imageTable = new ImageTable(this,test);
  }
  }
  
  </code></pre>
  <p>and xml file</p>
  <pre><code>
  &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;&gt;
  
  
      &lt;SurfaceView
          android:id=&quot;@+id/cylindersImage&quot;
          android:layout_width=&quot;358dp&quot;
          android:layout_height=&quot;219dp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintHorizontal_bias=&quot;0.49&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:layout_constraintVertical_bias=&quot;0.05&quot;&gt;
  
      &lt;/SurfaceView&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
  </code></pre>
  <p>onTouchEvent does not work with this way but if I set it by <code>test.setOnTouchListener(...)</code> it works. I think I should relate SurfaceView test with ImageTable but I don't know how to do. I also some drawing codes in ImageTable and they work properly, everything is drawn in SurfaceView test</p>
  <p>If I don't declare any SurfaceView on xml file and do <code>setContenView(new ImageTable(...))</code> and set surfaceHolder as <code>SurfaceHolder surfaceHolder = getHolder()</code> the event works.</p>