title: Is it possible to pass an onTouchEvent to multiple views in Android?
body: <p>I have read a few questions regarding this topic on SO but haven't really found a solid answer to it.</p>
  
  <p>I have a framelayout that I stack multiple custom views on, however the onTouch event only works with the top view. (the custom views are all the same view with the same onTouch event, just multiple of them)</p>
  
  <p><strong>FrameLayout</strong></p>
  
  <ul>
  <li>customView[2]  <em>&lt;--- this is the last view added and the only one that receives the event</em></li>
  <li>customView[1]</li>
  <li>customView[0]</li>
  </ul>
  
  <p>I'm testing it on Android 2.2 and am wondering if there is any way for the other views below to know where the touch happened?</p>
  
  <p><br></p>
  
  <p><strong>EDIT</strong> (Adding some code)</p>
  
  <p>I'm adding some code to hopefully help explain where I'm running into issues. At first I just automatically had the <code>onTouchEvent</code> return true. This made it so that the last view (in my case <strong>customerView[2]</strong>) would be the only one generating a value.</p>
  
  <p>However, once I added the method to set the <code>onTouchEvent</code> to return true or false, now the only view returning a generated value is <strong>customView[0]</strong>.</p>
  
  <p>I hope this clears up what I am asking. I'm rather new to this and I appreciate you taking the time to explain it (and of course I appreciate your patience).</p>
  
  <p>Also, I realize that my TextView's don't update with the value on each touchEvent, I'm working on fixing that.</p>
  
  <p>My Activity: </p>
  
  <pre><code>public class MyActivity extend Activity {
  
      CustomView[] customView;
      TextView[] textView;
      int numViews 3;
      //FrameLayout and Params created
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          for(int i = 0; i &lt; numViews; i++) {
              customView[i] = new CustomView(this, i);
  
  
              //Allows the onTouch to be handled by all Views - View[0] is the bottom view
              if(i == 0) {
                  customView[i].setTouchBool(true);        //set view's onTouch to return true
              } else {
                  customView[i].setTouchBool(false);       //set view's onTouch to return false
              }
  
              //Set TextView to display the number generated by the CustomView
              textView[i].setText(Double.toString(customView[i].getGeneratedNumber()));
  
              //Add views to main layout
              frame.addView(textView[i]);
              frame.addView(customView[i]);
          }
      }
  }
  </code></pre>
  
  <p>My View: </p>
  
  <pre><code>public class CustomView extends View {
  
      boolean onTouchHandler = true;
      int xVal = 0, yVal = 0;
      int index;
      double generatedNum = 0;
  
      public CustomView(Context context) {
          this(context, 0);
          this.index = 0;
      }
  
      public CustomView(Context context, int index) {
          super(context);
          this.index = index;
      }
  
  
      @Override 
      public boolean onTouchEvent(MotionEvent ev) {
          final int action = ev.getAction();
  
          switch(action) {
              case MotionEvent.ACTION_DOWN: {
                  //do logic 
              }
  
              case MotionEvent.ACTION_MOVE: {
                  //do logic
              }
  
              case MotionEvent.ACTION_UP: {
                  xVal = (int) ev.getX();
                  yVal = (int) ev.getY();
  
                  generateNumber(xVal, yVal, index);
  
                  break; 
              }
          }
           return onTouchHandler;    
      }  
  
  
      private void generateNumber(int x, int y, int index) {
          if(index == 0) {
              generatedNum = (x / 2) * (y / 2) + 64;
          } else {
              generatedNum = (x / 2) * (y / 2) + (index * 128);
          }
      }
  
      public double getGeneratedNumber() {
          return generatedNum;
      }
  
      public boolean setTouchBool(boolean b) {
          this.onTouchHandler = b;
      }
  }
  </code></pre>