开发者

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;
     }
 });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜