star
star

Reputation: 127

detect touched item changed without lifting up finger (swipe)

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 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.

Upvotes: 2

Views: 910

Answers (1)

Boris Karloff
Boris Karloff

Reputation: 1328

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;
    }
});

Upvotes: 2

Related Questions