0

When creating a custom element with attributes in Android I need to put the namespace of the application in the layout.

For example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:whatever="http://schemas.android.com/apk/res/org.example.mypackage"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

    <org.example.mypackage.MyCustomView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      whatever:my_custom_attribute="Hello, world!" />
</LinearLayout>

Does this also requires that the structure of my project in Eclipse be the same as the name of the Android package as definied in the Manifest - as per the example? Would this work too:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:whatever="http://schemas.android.com/apk/res/org.mycompany.myproduct"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

    <org.example.mypackage.MyCustomView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      whatever:my_custom_attribute="Hello, world!" />
</LinearLayout>
theblitz
  • 6,683
  • 16
  • 60
  • 114

1 Answers1

1

Its the package name of your application that should be reflected. So its correct to use it as you are doing.

For example:

In xmlns:whatever="http://schemas.android.com/apk/res/org.mycompany.myproduct the last part org.mycompany.myproduct should be the same as your package name. And you may change xmlns:whatever to anything like xmlns:theblitz but then make sure you do use theblitz as a prefix for your attributes in the xml.

For more info, read this

waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • I think you misunderstood what I meant (or I misunderstood your answer). In the first example, I used "org.mycompany.myproduct" both in the xmlns decleration AND in the declaration of the customer element. In tthe second one, the package in the custom element is "org.example.mypackage" and not "org.mycompany.myproduct". – theblitz May 13 '12 at 11:02
  • the view type `org.example.mypackage.MyCustomView` is defined in the same way as your class file is located – waqaslam May 13 '12 at 11:41
  • So, that and the value in the xmlns don't have to match - right? – theblitz May 14 '12 at 06:33
  • xmlns only needs to reflect package name. but the view type should reflect the full class path. So yes, both cant be matched as same – waqaslam May 14 '12 at 06:53