Reputation: 23
I am using "onTouchListener" in Android for a Button.
B.setOnTouchListener(
new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(G.AN,"ButtonID: "+B.getId());
mEvent = event.getAction();
Log.d(G.AN,"Event: " + mEvent);
H.post(RN);
return false;
}
}
);
"RN" is a runnable where I want to check at regular intervals if the button is still pressed. However, when I use isPressed() function, it always returns me "false"
@Override public void run() {
Log.d(G.AN,"ButtonID: "+B.getId());
switch(mEvent) {
case MotionEvent.ACTION_UP:
H.removeCallbacks(RN);
break;
case MotionEvent.ACTION_DOWN:
Delay = 300;
default:
**if(!B.isPressed())** {
Log.d(G.AN,"Button is not pressed");
return;
}
if(!IsIndex) { ........................
Does isPressed function really work? Any androiders out there who used it this way?
Thanks in advance...
Upvotes: 1
Views: 3629
Reputation: 5951
Try implement this:
B.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN ) {
Delay = 300;
return true;
}
else if (event.getAction() == MotionEvent.ACTION_UP ){
H.removeCallbacks(RN);
}
return false;
}
});
and you have to import:
import android.view.MotionEvent;
Upvotes: 1
Reputation: 1462
I am not sure...maybe u should call setpressed(true) in onTouch-method on ACTION.DOWN motionevent and setpressed(false) on ACTION_UP
Upvotes: 0