开发者

detect touched item changed without lifting up finger (swipe)

开发者 https://www.devze.com 2023-04-11 05:59 出处:网络
I have created two buttons in a gridview. I wish to achieve the following aim but no idea which method should be used?

I have created two buttons in a gridview.

I wish to achieve the following aim but no idea which method should be used?

First i touch on the 1st button, toast 1 msg will be shown. By swiping my finger over to the 2nd button 开发者_JS百科without lifting up my finger, toast 2 msg will be shown.

When i lift up my finger from the screen, toast 3 msg will be shown.


Maybe can help u

gridview.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {

        if(event.getAction() == MotionEvent.ACTION_MOVE){
            gridview.requestFocusFromTouch();
            gridview.setSelection(gridview.pointToPosition((int)event.getX(),(int)event.getY()));
            return true;
        }
        if(event.getAction() == MotionEvent.ACTION_UP){
            gridview.clearFocus();
            return true;
        }

        return false;
    }
});
0

精彩评论

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