Android 自定义视图“VideoView”已调用setOnTouchListener,但未覆盖performClick

Android 自定义视图“VideoView”已调用setOnTouchListener,但未覆盖performClick,android,Android,我得到一个自定义视图VideoView调用了setOnTouchListener,但没有覆盖performClick 片段: VideoView mContentView = (VideoView) findViewById(R.id.videoView); // Set up the user interaction to manually show or hide the system UI. mContentView.setOnTouchListener(mDelayHideTouchL

我得到一个自定义视图VideoView调用了setOnTouchListener,但没有覆盖performClick

片段:

VideoView mContentView = (VideoView) findViewById(R.id.videoView);
 // Set up the user interaction to manually show or hide the system UI.
mContentView.setOnTouchListener(mDelayHideTouchListener);


private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        show();
        if (AUTO_HIDE) {
            delayedHide(AUTO_HIDE_DELAY_MILLIS);
        }
        return false;
    }
};
有了此警告,应用程序在Android API24上运行正常,但在Android API23上应用程序崩溃


提前感谢您的帮助。

我认为标准视频视图不会覆盖performClick方法。 因此,您可以通过扩展自定义VideoView来处理此问题

myVideoView.java

package your.packagename.here;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

    public class myVideoView extends VideoView {
        public myVideoView(Context context) {
            super(context);
    }

    public myVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public myVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean performClick() {
        super.performClick();
        return true;
    }
}
// GLOBAL VARIABLE: isTouched (boolean)
        private void initActivity() {
            myVideoView vPlayer = findViewById(R.id.fullscreen_content);
            vPlayer.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    if(isTouched) return false;
                    switch (motionEvent.getAction()) {
                        case MotionEvent.ACTION_UP:
                            myVideoView vPlayer = (myVideoView)view;
                            vPlayer.seekTo(vPlayer.getDuration());
                            isTouched = true;
                            break;
                            default:
                                break;
                    }
                    view.performClick();
                    return true;
                }
            });
    }
playerActivity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    tools:context="your.packagename.here.playerActivity">
    <your.packagename.here.myVideoView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"/>
</RelativeLayout>

我认为标准的VideoView不会覆盖performClick方法。 因此,您可以通过扩展自定义VideoView来处理此问题

myVideoView.java

package your.packagename.here;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

    public class myVideoView extends VideoView {
        public myVideoView(Context context) {
            super(context);
    }

    public myVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public myVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean performClick() {
        super.performClick();
        return true;
    }
}
// GLOBAL VARIABLE: isTouched (boolean)
        private void initActivity() {
            myVideoView vPlayer = findViewById(R.id.fullscreen_content);
            vPlayer.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    if(isTouched) return false;
                    switch (motionEvent.getAction()) {
                        case MotionEvent.ACTION_UP:
                            myVideoView vPlayer = (myVideoView)view;
                            vPlayer.seekTo(vPlayer.getDuration());
                            isTouched = true;
                            break;
                            default:
                                break;
                    }
                    view.performClick();
                    return true;
                }
            });
    }
playerActivity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    tools:context="your.packagename.here.playerActivity">
    <your.packagename.here.myVideoView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"/>
</RelativeLayout>

为什么不重写这个方法呢?如果我只重写,那么它会显示onTouch方法上的另一个冲突。为什么不重写这个方法呢?如果我只重写,那么它会显示onTouch方法上的另一个冲突。