I’m trying to add a custom view in my xml file, code is like:
<View
android:id="@+id/myView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/radioGroupSensorRate"
android:layout_centerHorizontal="true"
class="com.zhangxaochen.mysensor.MyView" />
but then got runtime exceptions:
12-31 12:29:20.033: E/AndroidRuntime(4432): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zhangxaochen.mysensor/com.zhangxaochen.mysensor.MyGravitySensor}: java.lang.ClassCastException: android.view.View cannot be cast to com.zhangxaochen.mysensor.MyView
the class MyView has already been defined in my java file, I know the <com.packageName.ClassName attrs... /> way does work to add custom widgets, but i heard some saying that the second way is like that above <View class='com.zhangxaochen.mysensor.MyView' .../> , i tried and then failed. could anyone tell me how to fix that? or just that saying is fake?
Solved~
the second way:
<View class="packagename.ClassName" .../>doesn’t work is just because the tag ‘View’ being capitalized, it should be in lowercase: ‘view’…