onTouchListener with finger still on display

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

onTouchListener with finger still on display

Postby daliz » Fri Jul 10, 2009 2:15 pm

Hello,

I'm having a conceptual problem with a simple application.

I have an empty FrameLayout and I want for a certain event to being continuosly repeated until the finger leaves the display.

If I apply:

[syntax="java"]
frameLayout.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {

myEvent();

return false;
}
});
[syntax="java"]

I get a single instance of my event. But I want my event to be repeated until the finger stops touching.

How can I do?

Thank you :-)
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Top

Postby serkan.dogantekin » Mon Jul 13, 2009 11:43 pm

MotionEvent class has a method "getAction" to find out what kind of touch event is received (down, move, up etc.) For your case, you can start your event with MotionEvent.ACTION_DOWN and also declare a stop-control in your event that will be changed by MotionEvent.ACTION_UP
serkan.dogantekin
Developer
Developer
 
Posts: 27
Joined: Thu Jun 04, 2009 6:12 pm
Location: Istanbul/Turkey

Postby Moons » Tue Jul 14, 2009 10:57 am

Just return true instead of false
Moons
Developer
Developer
 
Posts: 25
Joined: Fri Feb 13, 2009 9:19 pm

Postby daliz » Tue Jul 14, 2009 8:37 pm

Thanks for the answer.

But are you sure I can use MotionEvent on a FrameLayout view?
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Postby Moons » Tue Jul 14, 2009 8:56 pm

You don't care about the Motion Event, just return true in the listener (as the doc you should have read says)
Moons
Developer
Developer
 
Posts: 25
Joined: Fri Feb 13, 2009 9:19 pm

Postby daliz » Tue Jul 14, 2009 10:08 pm

Ok, i solved with that. Thank you.

Now i have a little problem:

The main activity creates a custom view object. This custom view object should draw continuously something. BUT, as I can see, my (overridden) onDraw method is called once!

I could call object.draw(Canvas) from the main activity, but I have *not* a canvas to pass... it's inside the object!

How can i do? Really thank you.
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Top

Postby serkan.dogantekin » Tue Jul 14, 2009 10:17 pm

You can use view's invalidate method to trigger view's onDraw method
serkan.dogantekin
Developer
Developer
 
Posts: 27
Joined: Thu Jun 04, 2009 6:12 pm
Location: Istanbul/Turkey

Postby daliz » Tue Jul 14, 2009 11:46 pm

Great. Thank you.
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Postby daliz » Fri Jul 17, 2009 2:00 am

I noticed a thing in the solution you gave me:

An event is raised everytime I touch the display, everytime it moves on the display and everytime it leaves the display. But there are no events raised while the finger IS TOUCHING the display!

I'd like to have an event called continuously when the finger is touching.
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Postby daliz » Fri Jul 17, 2009 2:09 am

Update about my previous post:

the onTouch event is actually called continuously, but only on a real device. The emulator responds only when moving the "fake finger"... =)
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Postby serkan.dogantekin » Fri Jul 17, 2009 12:39 pm

i dont have an android based device so i am wandering; is this because of continuously detection of touch movements (small) through on touch screen?
serkan.dogantekin
Developer
Developer
 
Posts: 27
Joined: Thu Jun 04, 2009 6:12 pm
Location: Istanbul/Turkey

Postby daliz » Fri Jul 17, 2009 1:08 pm

I was thinking the same.
But I've been careful! If it's true, then the HTC Magic display is very very microscopic-sensitive to small touches! ... and I don't think so.
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests