tags:

views:

83

answers:

3

Is it possible to capture release of a button just as we capture click using onClickListener() and OnClick() ?

I want to increase size of a button when it is pressed and move it back to the original size when the click is released...can anyone help me how to do this?

+1  A: 

You might be able to do this by overriding the onKeyDown and onKeyUp. These are both inherited from android.widget.TextView. Please see the android.widget.Button doc for (a bit) more info.

mbanzon
onKeyDown and onKeyUp is for keyboard events if I am not wrong.Is is possible to capture click events for them?
mdv
+2  A: 

You should set an OnTouchListener on your button.

button.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event == MotionEvent.ACTION_DOWN) {
            increaseSize();
        } else if (event == MotionEvent.ACTION_UP) {
            resetSize();
        }
    }
};
cant0na
OnTouchListener listens only for touch right? I want to listen for click and release. How to go abt it?
mdv
A touch event down and up is practically a click. You could also set both an onclicklistener and an ontouchlistener on the button.
cant0na
ohhk...got it...thanx...
mdv
A: 

use an OnTouchListener or OnKeyListener instead.

kiki