0

So I have spent a long time looking to see if there is a solution for this. Basically, the below code allows me to press on a button, when I press (action_down) the 'pressed version' of the button is displaying good, then when I remove my finger the graphic returns to normal (action_up).

This part is working good BUT I need the ACTION_DOWN to stay active a little longer after the user presses the button and not return to ACTION_UP so fast. I can see lots of different people asking this question but no answers relating to editing the action_up or action_down part. I thought there must be some simple way to achieve this goal..

The current code:

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (MotionEvent.ACTION_DOWN == event.getAction()) {
        int img = Integer.parseInt(v.getTag(R.id.tag_press_down_img).toString());
        if (v instanceof ImageView) {
            ((ImageView) v).setImageResource(img);
        }

    } else if (MotionEvent.ACTION_UP == event.getAction()) {
        int img = Integer.parseInt(v.getTag(R.id.tag_press_up_img).toString());
        if (v instanceof ImageView) {
            ((ImageView) v).setImageResource(img);
        }
    }
    return false;
}

(This code is working fine but the user experience is bad because the button reverts back to ACTION_UP too fast (immediately) after being released - I would like ACTION_DOWN to 1) display for 1-2 seconds then revert back to ACTION_UP OR 2) remain in action_down until the called event is complete - in this case loading another screen).

Thank you!

tm_forthefuture
  • 185
  • 1
  • 12
  • why won't you try selector for imageview – Santhosh Feb 13 '14 at 13:08
  • Yes, I have looked at using selector but it can be messy and there is a lot more code involved. I wonder whether there is a more simple way to set it in the code above - one central location to change all locations of buttons etc. ALso not sure about options with timed display on selector – tm_forthefuture Feb 13 '14 at 13:16
  • I just tried selector again and it will not achieve what I want to do. Setting pressed, selected and normal states in selector just does exactly what I have already done - I want the button to behave differently from how it is behaving at the moment (please re-read my initial post). I can achieve a little more display time if set multiple states on the same graphic in an xml file but that is only because android has trouble handling it and not a good solution .. – tm_forthefuture Feb 13 '14 at 14:14

0 Answers0