0

我正在使用自定义视图寻呼机来禁用某些选项卡上的滑动。项目构建没有错误,但应用程序崩溃并出现以下错误:java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage/mypackage.activity}: java.lang.ClassCastException: android.support.v4.view.ViewPager cannot be cast到 mypackage.CustomViewPager

这行代码似乎失败了:

mViewPager = (CustomViewPager) findViewById(R.id.pager1);

这是自定义寻呼机代码:

public class CustomViewPager extends ViewPager {

//private boolean enabled;

public CustomViewPager(Context context) {
    super(context);
}

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

@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof WebView) {
        return true;
    }
    return super.canScroll(v, checkV, dx, x, y);
}

这里也是 XML 代码:

<mypackage.CustomViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

任何帮助将不胜感激!

4

0 回答 0