Touch events are delivered first to the inner-most view that is under the finger and then, if that view doesn't handle them, up to parents until either someone handles it or we reach the top of the hierarchy. If you want to intercept all touch events then you can override Activity.dispatchTouchEvent(), but this is a -really- rare thing to want to do and requires special care. If you just want to have a big view that the user touches in, you can make that your entire content view and receive touch events there.
On Oct 13, 1:33 pm, Rishi <[EMAIL PROTECTED]> wrote: > I was trying to implement OnTouch Event in my application, where user > could touch (move fingers) anywhere in the screen. I thought the best > way to do that would be, to set OnTouchListener on topmost layout. But > it appears, layouts does not receive all the motion events. Here is a > sample code - > > main.xml > ------------ > > <?xml version="1.0" encoding="utf-8"?> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > android" > android:id="@+id/topLayout" > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > > > <TextView > android:id="@+id/txtHello" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:text="Hello!" > /> > </LinearLayout> > > public class Hello extends Activity { > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > View topLayout = this.findViewById(R.id.topLayout); > HelloOnTouchListener l = new HelloOnTouchListener(); > topLayout.setOnTouchListener(l); > } > > class HelloOnTouchListener implements OnTouchListener{ > > @Override > public boolean onTouch(View arg0, MotionEvent arg1) { > // TODO Auto-generated method stub > > Log.i(tag, arg0 + " " + arg1.getAction()); > return false; > } > } > > private static final String tag = Hello.class.getName(); > > } > > When I touch it prints the ACTION_DOWN MotionEvent, but nothing else. > There is no ACTION_MOVE or ACTION_UP. Am I missing any thing? > > I'll really appreciate you help. > > Thanks, > Rishi --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

