Search code examples
androidandroid-imageviewonlongclicklistener

How make something after long click?


I set onLongClickListener on ma imageView. I have a question - how can i do something after longclick? For example :

imageView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            imageView.setVisibility(View.INVISIBLE);

            return true;
        }
    });

and after the longClick i would set Visibile my imageView. How can I do this?


Solution

  • Copy this and replace it with your code Use on touch listener instead

    view.setOnTouchListener(new imageView.OnTouchListener() {        
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // PRESSED
                return true; // if you want to handle the touch event
            case MotionEvent.ACTION_UP:
                // RELEASED
                return true; // if you want to handle the touch event
        }
        return false;
    }
    

    });