Android: Why can't I give an onClickListener t

2019-03-14 05:46发布

I have written these lines of code:

 mVideoView = (VideoView) findViewById(R.id.video_view);
    mVideoView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.v("LOG_TAG, click");
        }
    });

However, when I run my application, the click event is never called.

So I wonder, is it impossible to register an OnClickListener on a VideoView? And, if so, why is that the case?

10条回答
我只想做你的唯一
2楼-- · 2019-03-14 06:14

use VideoView.setOnTouchListener(..) it works for VideoView

查看更多
The star\"
3楼-- · 2019-03-14 06:16

The VideoView is a wrapper containing mdeiaplayer and surfaceView. You can interact with through MediaController or writing your own SurfaceView and implement onClick events.

查看更多
男人必须洒脱
4楼-- · 2019-03-14 06:18

I realize this is an old question but thought I'd chime in with an easy workaround. I can't answer why this doesn't work - seems like a big oversight in my opinion. But an easy workaround is to place your VideoView as the sole View inside a FrameLayout, and set an OnClickListener on the layout. Not ideal, but it works.

查看更多
劳资没心,怎么记你
5楼-- · 2019-03-14 06:19

It is possible I have did this with onSetClickListener. And Here's a code for your help:

mVideoView.setOnClickListener(new View.OnClickListener() {
    @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //Here you put a condition for playing a video when you click on your video view.//
            if(my_video.isPressed())
            {   
                my_video.start();
            } else {
                Toast.makeText(getApplicationContext(), 
                    "Not able to run This Video!", 
                    Toast.LENGTH_LONG).show();
            }
        }
    });
查看更多
登录 后发表回答