onTouchListener not working

前端 未结 3 2170
青春惊慌失措
青春惊慌失措 2021-02-19 04:13

I have the following code in my activity. In my xml, the video view is inside the linear layout. However, when the view is clicked, the onTouchListener never fires.

相关标签:
3条回答
  • Modify your code like this and try:

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.d(TAG, "onTouch entered");
        if(event.getAction() == MotionEvent.ACTION_UP) {
            Log.d(TAG, "ACTION_UP");
            return super.onTouchEvent(event);
        else
            return false;
    }
    
    0 讨论(0)
  • 2021-02-19 04:44

    ACTION_UP is never being sent to your listener because you return false and therefor don't "consume" the event. Return true and you'll get the start event (ACTION_DOWN) as well as all the subsequent ones (ACTION_MOVE and then ACTION_UP).

    0 讨论(0)
  • 2021-02-19 04:53

    i have faces this issue and the solutions is:-

    1-in your xml set the followin attribute to VideoView

    android:clickable="true"

    2- simply in your code set setOnClickListenerto the VideoView and it will work like charm:

    videoView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(CinemaDetailsActivity.this , FullScreenPlayerActivity.class);
            intent.putExtra("url" ,  getIntent().getStringExtra("url"));
            startActivity(intent);
        }
    });
    
    0 讨论(0)
提交回复
热议问题