Android: onTouch() never gets called?
<p>Hi everyone
I am playing with UI Event Handling, and I have found something that I cannot find the explanation from the <a href="http://developer.android.com/guide/topics/ui/ui-events.html#EventListeners" rel="nofollow">Android Dev</a>: I have an ImageView, and a TextView , whenever I touch on the ImageView, the TextView show a message. But the following codes doesn't work:</p>

<pre><code>    public class ShowSomething extends Activity {
 private LinearLayout ll;

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);  

  LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout);
  final TextView textview = (TextView)findViewById(R.id.textview);
  MyImageView image = new MyImageView(this, textview);
  image.setImageResource(R.drawable.icon);
  ll.addView(image, 48, 48);

 }
}
</code></pre>

<p>And MyImageView.java</p>

<pre><code>public class MyImageView extends ImageView implements OnTouchListener{


 private TextView textview;

 public MyImageView(Context context,TextView textview) {
  super(context);
  this.textview = textview;
 }

 @Override
 public boolean onTouch(View v, MotionEvent event) {
  textview.setText("Event captured !");
  return true;
 }
}
</code></pre>

<p>main.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
&gt;
&lt;TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Holder"
/&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>But when I attach an OnTouchListener on the MyImageView like this, it does work:
File ShowSomething.java</p>

<pre><code>public class ShowSomething extends Activity {

 private LinearLayout ll;

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);  

  LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout);
  final TextView textview = (TextView)findViewById(R.id.textview);


  MyImageView image = new MyImageView(this,textview);
  image.setImageResource(R.drawable.icon);
  image.setOnTouchListener(new OnTouchListener() {  
     @Override
     public boolean onTouch(View v, MotionEvent event) {
      textview.setText("Event captured!");      
      return false;
     }
    });
  ll.addView(image, 48, 48);

 } 

}
</code></pre>

<p>And file MyImageView.java</p>

<pre><code>public class MyImageView extends ImageView { 


 private TextView textview;

 public MyImageView(Context context,TextView textview) {
  super(context);
  this.textview = textview;
 }


}
</code></pre>

<p>But as far as I know, the 2 implementation is the same (implement an Event Listener) - do I misunderstand anything ?</p>
