开发者

Android turning clicks into touches

开发者 https://www.devze.com 2023-04-09 03:48 出处:网络
I have an on click listener: whiteKeyPressedArray[i].setOnClickListener(new View.OnClickListener() { public void onClick(V开发者_运维问答iew v) {

I have an on click listener:

whiteKeyPressedArray[i].setOnClickListener(new View.OnClickListener() {
               public void onClick(V开发者_运维问答iew v) {
}}

I see that this allows touches:

public boolean onTouch(View v, MotionEvent event) {

//Switch case for type of touch
}

But how can I detect touch rather than click on my whiteKeyPressedArray[i]?

Thanks!


OnTouch will fire many many times :), actually onTouch will be trigered over and over again as long as you keep your finger to that element (as long as you touch that element). Where onClick will be fire just ones but ONLY if you return false from your onTouch handler.


I don't know what the whiteKeyPressedArray[i] is, but have you tried:

whiteKeyPressedArray[i].setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        return true; // or false if you want the event to pass on
    }
});

Maybe this is what you are looking for?

0

精彩评论

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

关注公众号