Hold the image and send to link in Android Studio

Asked

Viewed 58 times

2

Hold the image and send to link in Android Studio I use an Imageview that when I click performs a function, but I would like when the image was pressed, another action was done, which would be different from just a simple touch on the image. That is, Imageview with 2 functions, 1 simple touch and the other pressing the image. How creates this function to press the image?

Thank you

  • Could add your layout?

  • @Lennoardsilva I asked a question detailing https://answall.com/questions/329922/clique-normal-e-longo-s%C3%B3-run-ap%C3%B3s-give-a-first-click-on-imageview

1 answer

1

For simple touch, use the method setOnClickListener and to press use setOnLongClickListener.

Follow an example:

  imageView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(getApplicationContext(), "LongClick! ", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "Click! ", Toast.LENGTH_SHORT).show();
        }
    });
  • I did it, but it does not work on the first click, need to give a click and after it there yes, it works the two functions, click and long.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.