I am having problem with invoking a custom component in my Android projects in Eclipse. It seem that I do not understand how the namespace declarations belong together. I have checked several other threads here at SO, which at first seem to be related, but I cannot solve my problem with these:
- android-custom-control-namespace-issue
- how-to-pass-custom-component-parameters-in-java-and-xml
- android-custom-widget-styles-how-to-put-them-into-a-namespace
I have the following set-up (code is anonymized):
/values/extra_attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="extraComponent">
<attr name="count" format="integer" />
</declare-styleable>
</resources>
/layout/extra_main.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/extra_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/extra_main"
/>
</merge>
/com.site.package.extra/extra.java
package com.site.package.extra;
... misc imports...
public class Extra extends FrameLayout
{
... misc code...
}
/com.site.package/main.java (start-up class)
package com.site.package;
... misc imports...
public class Main extends Activity
{
... misc code...
}
/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/main_style"
xmlns:extra="http://schemas.android.com/apk/res/com.site.package" >
<com.site.package.Extra
android:layout_width="wrap_content"
android:layout_height="wrap_content"
extra:count="3">
</com.site.package.Extra>
</RelativeLayout>
The problem I face is; whatever I do, I cannot manage to invoke my custom component. The errors occur in may layout and I have tried to change the following items:
- name space declaration
xmlns:extra="http://schemas.android.com/apk/res/com.site.package"
xmlns:extra="http://schemas.android.com/apk/res/com.site.package.extra"
xmlns:extra="http://schemas.android.com/apk/res/extra"
- component invokation
<com.site.package.extraComponent />
<com.site.package.Extra.extraComponent />
<extraComponent />
<Extra.extraComponent />
<android.view.ext.extraComponent />
- attributes
extra:count="3"
com.site.package.extra:count="3"
In neither case I manage to get any help from intellisense so I am completely lost. I really do not understand how the namespaces are working here and how I should put the code to work.
EDIT :
I forgot to include my AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.site.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_logo"
android:label="MyApp"
android:name="MyApp" >
<activity
android:label="MyApp"
android:name=".Main" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</manifest>