onTouchEvent and onKeyDown creats problem????

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

onTouchEvent and onKeyDown creats problem????

Postby ShanuSaxena » Thu Jan 29, 2009 7:46 am

hey guys......
i was wondering weather onTouchEvent and onKeyDown in a same view under a same activity creates problem.
bcos m facing problem wid these two wen i touch the screen den onKeyDown doesn't recognize key event.....

i hv attached a simple code wid problem.....m a newbie in android programming so m not much familiar wid any flags or methods to get this work right......

P.S.: if we move trackball just after touch it works but any other key just after touch doesn't work...
Attachments
TestView.java
(1.13 KiB) Downloaded 63 times
testTouch.java
(457 Bytes) Downloaded 63 times
Last edited by ShanuSaxena on Sat Feb 07, 2009 10:33 am, edited 2 times in total.
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Top

Postby hebbalhrk » Tue Feb 03, 2009 9:19 am

Please describe ur problem.
What exactly you want to do onTouch and onKey events?
hebbalhrk
Developer
Developer
 
Posts: 37
Joined: Wed Jun 18, 2008 10:35 am

Postby jjaaxx44 » Fri Feb 06, 2009 6:57 pm

hey,
m facing same problem, problem with particular code is when screen is touched and just after that any key is pressed onKeyDown wont get called. only trackball event is recognized just after touching event.
u can see it easily by running code given code.
jjaaxx44
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 31, 2009 4:44 am

Postby ShanuSaxena » Sat Feb 07, 2009 10:38 am

hi all,

ya u right jaxx it is same problem in my code....

and one more problem coming when we touch the screen in the application, its works like a fireKeyPressed() but i want that its works like a fireKeyReleased().. is it possible....? plz give me solution if any......
my sample code...use in app..

public boolean onTouchEvent(MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
switch (currentState) {
case SHOW_MAINMENU:
................
......
break;
}
break;
}

return super.onTouchEvent(event);
}
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Postby hebbalhrk » Mon Feb 09, 2009 5:53 am

Try the android.view.GestureDetector.OnGestureListener
Say you want to enable touch gestures on a button.

findViewById(R.id.buttonid).setOnTouchListener(
new View.OnTouchListener() {
gestureDetector.onTouchEvent(event);
}

return true;
}
});



final GestureDetector gestureDetector = new GestureDetector(
new GestureDetector.SimpleOnGestureListener() {

//For single click touch gestures use onSingleTapUp
public boolean onSingleTapUp(final MotionEvent e) {
//Do something here on tap or click...

return true;
}

//For swipe touch gestures use onFling
public final boolean onFling(final MotionEvent e1,
final MotionEvent e2, final float velocityX, final float velocityY) {

return true;
}

});


Refer,
http://code.google.com/android/referenc ... tener.html
hebbalhrk
Developer
Developer
 
Posts: 37
Joined: Wed Jun 18, 2008 10:35 am

Postby ShanuSaxena » Mon Feb 09, 2009 11:09 am

hi hebbalhrk thanx for reply...

but it is not a button. It is some area on the screen. just like small box... i want to create touch-event but problem is that it is working on touch...not touch release....just like KeyReleased()...
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Top

Postby hebbalhrk » Tue Feb 10, 2009 1:25 pm

Check out the attachment for a sample touch gesture demo.
It uses touch events to drag and drop an image.
Attachments
Drag.rar
(29.58 KiB) Downloaded 67 times
hebbalhrk
Developer
Developer
 
Posts: 37
Joined: Wed Jun 18, 2008 10:35 am

Postby ShanuSaxena » Fri Feb 13, 2009 12:01 pm

hi hebbalhrk thank for reply,
i do this for simple touchEvent.....
but my problem is trackball press is not working after just touchEvent, it works when we trackball up or down or left to right....
other problem is touchevent works only finger down(touch on image..), but i want touchevent works on finger release on image..
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Postby Cymon_NL » Thu Feb 19, 2009 11:23 am

Switching between modes can be a problem sometimes. However, this is an Android architectual choice. Read this: http://android-developers.blogspot.com/ ... -mode.html
(Sorry I cannot make the link clickable. I am a first-time user at this forum so I have to post something first, or something. :-) )

Edit: hey wait, the link is clickable anyhow. I just cannot say [url = ...]and stuff.
User avatar
Cymon_NL
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Feb 19, 2009 11:14 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 2 guests