How to determine a long listener when viewing an image?

I am developing an Android application. In my application, I have one kind of image. I want to identify a long press listener when viewing an image, when I click on the image that I want to vibrate on the device for a long time. How is this possible? Thanks everyone

+6
android
source share
3 answers

You can try to do it like this:

ImageView imageView = (ImageView) findViewById(R.id.ImageView); final Vibrator vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE); imageView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { vibrator.vibrate(100); return true; } }); 
+16
source share

you can try this

 ImageView iv = (ImageView) findViewById(R.id.ImageView); iv.setOnLongClickListener(vlong); private View.OnLongClickListener vLong = new View.OnLongClickListener() { public boolean onLongClick(View view) { // do any thing return true; } }; 
+2
source share

You must set clickable true in the view. try setLongClickable (true)

 ImageView imageView = (ImageView) findViewById(R.id.imgView); imageView.setLongClickable(true); final Vibrator vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE); imageView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { vibrator.vibrate(100); return true; } }); 
+1
source share

All Articles