Custom namespace vs. null namespace: Android best practice -


when developing android user interfaces, should define custom namespaces or use null namespaces? , why?

as concrete example. consider following:

custom namespaces

layout/main.xml:

<com.example.myexample     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:custom="http://schemas.android.com/apk/res/com.example"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     custom:customstring="test string"/>  

res/attrs.xml:

<declare-styleable name="myexample">     <attr name="customstring" format="string" /> </declare-styleable> 

src/com/example/myexample.java:

layoutinflater.from(context).inflate(r.layout.my_example, this, true);    ((textview)findviewbyid(r.id.textview)).settext(     attrs.getattributevalue("http://schemas.android.com/apk/res/com.example", "customstring") ); 

null namespaces

layout/main.xml:

<com.example.myexample     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     customstring="test string"/>  

src/com/example/myexample.java:

layoutinflater.from(context).inflate(r.layout.my_example, this, true);    ((textview)findviewbyid(r.id.textview)).settext(     attrs.getattributevalue(null, "customstring") ); 

custom namespaces necessary if have more 1 library project same attribute names. or if writing library project should use them in case else using same named atrributes. otherwise recommended.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -