自定义视图不会覆盖performClick()错误 - Android

时间:2015-04-02 18:44:29

标签: android ontouchlistener android-scrollview

我正在尝试使用自定义Horizo​​ntalScrollView在从this website滚动时具有类似画廊的效果。但是,我收到此错误:Custom view HorizontalScrollViewCustom has setOnTouchListener called on it but does not override performClick。我查看了几个没有帮助的StackOverflow答案,我尝试在this solution中添加performClick()方法,但我的performClick()方法有错误The method performClick() of type new View.OnTouchListener(){} must override or implement a supertype method

这里有相关代码:

final HorizontalScrollViewCustom hoScro = (HorizontalScrollViewCustom) findViewById(R.id.ho_scro);
    View.OnTouchListener mTouchListener = new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //If the user swipes
            if (hoScro.mGestureDetector.onTouchEvent(event)) {
                return true;
            }
            else if(event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL ){
                int scrollX = hoScro.getScrollX();
                int featureWidth = v.getMeasuredWidth();
                hoScro.mActiveFeature = ((scrollX + (featureWidth/2))/featureWidth);
                int scrollTo = hoScro.mActiveFeature*featureWidth;
                hoScro.smoothScrollTo(scrollTo, 0);
                v.performClick();
                return true;
            }
            else{
                return false;
            }
        }
        @Override
        public boolean performClick() {
            // tried adding this method to get rid of warning, but didn't work
            super.performClick();
            return true;
        }

    };
    hoScro.setOnTouchListener(mTouchListener);

0 个答案:

没有答案