开发者

Using an Android Long-Button press to increment/decrement counter

I want to be able to press a button on my program and hold it down (without releasing) to increment a variable. Problem I am having right now is when I conduct the long button press it only runs once, until I release and press again.

First I want to find out if there is a way to do this without having to use the OnTouchListener, and just using the OnLongClick. Is there a way to check the value of the button? For example.. buttondown=true; Conduct a whileloop to increment until the button is released.

Second, I don't want开发者_开发问答 the updates to be delayed, because the incremented value is being drawn as the user holds down the button.

Basically I am doing something like this:

btn_resume.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {


..code..
return true;

        }
    });


OnLongClick will only be called once per press. It isn't going to work for your purpose.


If I understood your question correct this can be achieved using a OnLongClickListener.


Check http://developer.android.com/reference/android/view/View.html#setOnTouchListener(android.view.View.OnTouchListener)

OnTouchListener provides a more granular handling of touch events, e.g. KeyDown, KeyUp


I think you can use OnLongClickListener for increment/decrement. But once the long press is done for the button, the longpress has to be canceled or reset for the next long press of the same button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜