Archive for November, 2011

Escaping Angle Brackets in XML in Android

November 20, 2011

Either specify those characters like this:

< = &lt; > = &gt; 

Or use a CDATA section and put those characters inside:

<![CDATA[<]]> <![CDATA[>]]>

Here.

Accessing resources in Android

November 20, 2011

In most cases, you need to get hold of the Context object in order to access the resources in the app (the local package). Because Activity extends Context, you can get all the resources accessible from an instance of Context. For example:

Context.getResources().getString(R.string.resName);

or simply

Context.getString(R.string.resName);

If you want to access the resources in the local package from an object that doesn’t inherit from Context, you need to pass the context object to it somehow. On the other hand, you can access the resources provided by the system (Android) without any context object:

final Resources r = Resources.getSystem();
r.getString(android.R.string.untitled);

Here.


Follow

Get every new post delivered to your Inbox.