我已经扩展了微调器类以便自定义它,但我无法弄清楚如何在我的代码中使用它。
public class mySpinner extends Spinner {
......
}
我有一个使用微调器的现有活动,我想将其更改为使用mySpinner类。
最初:
Spinner spinner = (Spinner) textEntryView
.findViewById(R.id.account_spinner);
和
<Spinner
android:id="@+id/account_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/ADALabel1"
android:layout_alignLeft="@+id/newassetsymbol"
android:layout_below="@+id/assetclass_spinner" />
首先我尝试了:
mySpinner spinner = (Spinner) textEntryView
.findViewById(R.id.account_spinner);
编译错误(有意义)。 然后我试了一下:
mySpinner spinner = (mySpinner) textEntryView
.findViewById(R.id.account_spinner);
运行时强制转换错误。 然后我用前一行改变了布局:
<mySpinner
android:id="@+id/account_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/ADALabel1"
android:layout_alignLeft="@+id/newassetsymbol"
android:layout_below="@+id/assetclass_spinner" />
01-12 06:50:02.664:E / AndroidRuntime(597):引起:java.lang.ClassNotFoundException:loader dalvik.system.PathClassLoader中的android.view.mySpinner [/data/app/org.sample。样品1.apk]
这似乎并不难,但我错过了一些东西。有人可以帮忙吗? 谢谢。
答案 0 :(得分:1)
在XML中使用自定义View
组件时,您需要使用完整的类路径。
<com.example.appname.mySpinner />