How to use my own view in the layout?

I created a class like this

public final class MyView extends View { public MyView(Context context, AttributeSet attrs) { super(context, attrs); [...] } [...] } 

and then I want to use it in my layout.xml

 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.hitziger.barcode.MyView android:id="@+id/my_view" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </FrameLayout> 

But Eclipse tells me in the error log

AndroidManifest: ignoring unknown 'com.hitziger.barcode.MyView' XML Element

How to make MyView available in layout? Should I publish this class elsewhere?

+7
source share
2 answers

You should write this as:

 <view class="com.hitziger.barcode.MyView"... 
+11
source

in layout.xml, use:

 <View android:class="com.hitziger.barcode.MyView" android:id="@+id/my_view" ... 

istead of:

 <com.hitziger.barcode.MyView android:id="@+id/my_view" 
0
source

All Articles