我正在尝试创建一个自定义ViewPager,它将阻止用户滚动,因为它应该只能以编程方式移动,根据另一个经典的ViewPager。当我使用两个经典寻呼机时,两个寻呼机之间的链接正在工作,我只需要删除其中一个寻呼机的触摸处理(如果有任何解决方案比创建自定义寻呼机更简单,那么它将无法完全回答问题但是仍然是我问题的有效解决方案)
这是我的自定义分页器类:
namespace MyApplication.Droid
{
public class NonSwipeableViewPager : ViewPager
{
public NonSwipeableViewPager(Context context) :
base(context)
{
Initialize();
}
public NonSwipeableViewPager(Context context, IAttributeSet attrs) :
base(context, attrs)
{
Initialize();
}
public NonSwipeableViewPager(IntPtr javaReference, JniHandleOwnership transfer) :
base(javaReference, transfer)
{
Initialize();
}
void Initialize()
{
}
}
}
根据这个,我班级的完全限定名称是
MyApplication.Droid.NonSwipeableViewPager
这是我尝试在AXML布局中使用它:
<myapplication.droid.NonSwipeableViewPager
android:id="@+id/nonSwipeableViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
但结果总是一样的。根据堆栈跟踪(见下文),无法找到类。
Android.Views.InflateException: Binary XML file line #1: Error inflating class myapplication.droid.NonSwipeableViewPager ---> Java.Lang.ClassNotFoundException: Didn't find class "myapplication.droid.NonSwipeableViewPager" on path: DexPathList[[zip file "/data/app/com.company.myapplication-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.company.myapplication-1, /system/lib]]
at java.lang.ClassNotFoundException: Didn't find class "myapplication.droid.NonSwipeableViewPager" on path: DexPathList[[zip file "/data/app/com.company.myapplication-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.company.myapplication-1, /system/lib]]
at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at at md55dff054c92df00b604ae7ee631274a9a.AppointmentRequestFragment.n_onCreateView(Native Method)
at at md55dff054c92df00b604ae7ee631274a9a.AppointmentRequestFragment.onCreateView(AppointmentRequestFragment.java:35)
at at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
at at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
at at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
at at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
at at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
at at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
at at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
at at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
at at android.os.Handler.handleCallback(Handler.java:733)
at at android.os.Handler.dispatchMessage(Handler.java:95)
at at android.os.Looper.loop(Looper.java:136)
at at android.app.ActivityThread.main(ActivityThread.java:5001)
at at java.lang.reflect.Method.invokeNative(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:515)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at at dalvik.system.NativeStart.main(Native Method)
--- End of inner exception stack trace ---
首先,我不知道我必须小写axml中的命名空间(从MyApplication.Droid到myapplication.droid)。
我尝试了几件事,比如根据命名空间保留大小写,除了类名之外全部小写,只降低命名空间各部分的第一个字母,但是所有内容都会导致同样的错误,我不明白为什么。我错过了什么吗?
答案 0 :(得分:1)
错误类myapplication.droid.NonSwipeableViewPager
正如您所指出的,您应该使用自定义类的完全限定名称,如下所示:
<MyApplication.Droid.NonSwipeableViewPager
android:id="@+id/nonSwipeableViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>