Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define custom Android components using short namespace?

Tags:

android

Working on my first Android application. I'm wondering if there's a way to use the xmlns in the markup in any way. In Flex, for example, I can define a namespace:

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:cb="com.typeoneerror.apps.app.views.components.*">
    <cb:CustomComponent paramName="demo"></cb:CustomComponent>
</mx:VBox>

Android seems to be slightly different. You use the namespace when defining params but not the tag itself. This is a bit wordy to me, so I'm wondering if there's a way to configure or change this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cb="http://schemas.android.com/apk/res/com.typeoneerror.apps.app">
    <com.typeoneerror.apps.app.views.components.CustomComponent cb:paramName="demo"/>
</LinearLayout>

I'd like to use

<cb:CustomComponent cb:paramName="demo"></cb:CustomComponent>

Possible?

like image 867
typeoneerror Avatar asked Jan 27 '11 20:01

typeoneerror


People also ask

What is FindViewById () method used for?

FindViewById(Int32)Finds a view that was identified by the android:id XML attribute that was processed in #onCreate .

What are namespaces in Android?

In an XML file, namespaces are used to provide elements and attributes with distinctive names. Names for elements or attributes in an XML instance may come from different XML vocabularies.


1 Answers

No, sorry. The element name is a Java class name, and in the case of custom widgets, is a fully-qualified class name.

I have seen some syntax where the element name is View and there is a class attribute with the widget's class name. I can't find that in the docs and don't have an sample available, though.

like image 188
CommonsWare Avatar answered Sep 23 '22 21:09

CommonsWare