开发者

Android turning clicks into touches

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜