Thursday, 24 January 2013

Android Development Tutorial (Based on Android 4.1) class-5

Resources


1. Resources


Android supports that resources, like images and certain XML configuration files, can be keep separate from the source code.

These resources must be defined in the res directory in a special folder dependent on their purpose. You can also append additional qualifiers to the folder name to indicate that the related resources should be used for special configurations, e.g. you can specify that a resource is only valid for a certain screen size.

The following table give an overview of the supported resources and their standard folder prefix.

Resources

The gen directory in an Android project contains generated values. R.java is a generated class which contains references to certain resources of the project.

If you create a new resource, the corresponding reference is automatically created in R.java via the Eclipse ADT tools. These references are static integer values and define IDs for the resources.

The Android system provides methods to access the corresponding resource via these IDs.

For example to access a String with the R.string.yourString ID, you would use the getString(R.string.yourString)) method.

R.java is automatically created by the Eclipse development environment, manual changes are not necessary and will be overridden by the tooling.

2. Assets


While the res directory contains structured values which are known to the Android platform, the assets directory can be used to store any kind of data. You access this data via the AssetsManager which you can access the getAssets() method.

AssetsManager allows to read an assets as InputStream with the open() method.

Assets

3. Defining IDs


Android allows that you define ID of user interface components dynamically in the layout files, via the @+id/your_id notation.

To control your IDs you can also create a file called ids.xml in your /res/values folder and define all IDs in this file.

Defining-IDs

This allow you to use the ID directly in your layout file.

Defining-IDs1

Related Topics : Android Development Tutorial (Based on Android 4.1) class-1

Android Development Tutorial (Based on Android 4.1) class-2


Android Development Tutorial (Based on Android 4.1) class-3


Android Development Tutorial (Based on Android 4.1) class-4

No comments:

Post a Comment