Android: Why can't I give an onClickListener to a VideoView?

前端 未结 11 2142
独厮守ぢ
独厮守ぢ 2021-02-03 17:08

I have written these lines of code:

 mVideoView = (VideoView) findViewById(R.id.video_view);
    mVideoView.setOnClickListener(new OnClickListener() {
        @O         


        
11条回答
  •  忘了有多久
    2021-02-03 17:24

    I know this is and old question, but here is what I did:

    Since setOnClickListener is not been triggered, I created my own class which extends VideoView

    public class VideoViewCustom extends VideoView{
    

    and Overrided the onTouchEvent

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
    
        if(ev.getAction() == MotionEvent.ACTION_DOWN){
            Log.d(TAG, "ACTION_DOWN");
        }
    
        return super.onTouchEvent(ev);
    }
    

    and now I can get the onClick event with the MotionEvent.

    Hope this helps someone!

提交回复
热议问题