【发布时间】:2012-05-06 04:49:57
【问题描述】:
我有一个应用程序,它有一个使用ScrollView 的活动。我需要检测用户何时到达ScrollView 的底部。我做了一些谷歌搜索,我找到了this page 的解释。但是,在示例中,这些人扩展了ScrollView。正如我所说,我需要扩展 Activity。
所以,我说“好吧,让我们尝试创建一个扩展 ScrollView 的自定义类,重写 onScrollChanged() 方法,检测滚动的结束,并采取相应的行动”。
我做了,但在这一行:
scroll = (ScrollViewExt) findViewById(R.id.scrollView1);
它会抛出一个java.lang.ClassCastException。我在我的 XML 中更改了 <ScrollView> 标记,但显然它不起作用。我的问题是:为什么,如果ScrollViewExt 扩展ScrollView,会向我扔ClassCastException?有什么方法可以检测滚动结束而不会造成太多混乱?
谢谢大家。
编辑: 正如所承诺的,这是我的 XML 中重要的部分:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="@+id/textterms"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:textColor="@android:color/black" />
</ScrollView>
我将它从 TextView 更改为 WebView 以便能够证明里面的文本。我想要实现的是“在完全阅读合同条款之前,接受按钮不会激活”的事情。我的扩展类称为ScrollViewExt。如果我将标签 ScrollView 更改为 ScrollViewExt 它会抛出一个
android.view.InflateException: Binary XML file line #44: Error inflating class ScrollViewExt
因为它不理解标签ScrollViewEx。我不认为它有解决方案...
感谢您的回答!
【问题讨论】:
-
不需要自定义类或复杂的扩展。只需使用
canScrollVertically(int)
标签: android android-scrollview