“On Touch Listener Android” Kode Jawaban

On Touch Listener Android

imageButton.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_UP){

            // Do what you want
            return true;
        }
        return false;
    }
});
Worried Wren

On Touch Listener Android

private View.OnTouchListener handleTouch = new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {

        int x = (int) event.getX();
        int y = (int) event.getY();

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("TAG", "touched down");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.i("TAG", "moving: (" + x + ", " + y + ")");
                break;
            case MotionEvent.ACTION_UP:
                Log.i("TAG", "touched up");
                break;
        }

        return true;
    }
};
Worried Wren

Jawaban yang mirip dengan “On Touch Listener Android”

Pertanyaan yang mirip dengan “On Touch Listener Android”

Lebih banyak jawaban terkait untuk “On Touch Listener Android” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya