on touch listener android

Solutions on MaxInterview for on touch listener android by the best coders in the world

showing results for - "on touch listener android"
Winston
29 Oct 2017
1imageButton.setOnTouchListener(new OnTouchListener() {
2    @Override
3    public boolean onTouch(View v, MotionEvent event) {
4        if(event.getAction() == MotionEvent.ACTION_UP){
5
6            // Do what you want
7            return true;
8        }
9        return false;
10    }
11});
12
Nicole
19 Aug 2016
1private View.OnTouchListener handleTouch = new View.OnTouchListener() {
2
3    @Override
4    public boolean onTouch(View v, MotionEvent event) {
5
6        int x = (int) event.getX();
7        int y = (int) event.getY();
8
9        switch (event.getAction()) {
10            case MotionEvent.ACTION_DOWN:
11                Log.i("TAG", "touched down");
12                break;
13            case MotionEvent.ACTION_MOVE:
14                Log.i("TAG", "moving: (" + x + ", " + y + ")");
15                break;
16            case MotionEvent.ACTION_UP:
17                Log.i("TAG", "touched up");
18                break;
19        }
20
21        return true;
22    }
23};
24