How to determine long press listener on image view?
I am dev开发者_JAVA百科eloping an android application. In my application,I have one image view. I want to determine long press listener on image view,when I long press on image i want to vibrate device.How is possible? Thanks all
You can try to do it this way:
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;
}
});
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;
}
};
You have to set clickable true on 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;
}
});
精彩评论