Resources and the R class

The folders under res/ in the Eclipse project are for resources. There is aspecific structure to the folders and files under res/. Resources defined in these folders and files will have corresponding entries in the R class allowing them to be easily accessed and used from your application. The R class is automatically generated using the contents of the res/ folder by the eclipse plugin (or by aapt if you use the command line tools). Furthermore, they will be bundled and deployed for you as part of the application.

To make the list of notes in the ListView, we also need to define a View for each row:

1. Create a new file under res/layout called notes row.xml.

2. Add the following contents (note: again the XML header is used, and the first node defines the Android XML namespace)

<?xml version="1.0" encoding="utf-8"?> <TextView android:id="@+id/text1"

xmlns:android="" android:layout width="wrap content" android:layout height="wrap content"/>

This is the View that will be used for each notes title row — it has only one text field in it.

In this case we create a new id called textl. The + after the @ in the id string indicates that the id should be automatically created as a resource if it does not already exist, so we are defining textl on the fly and then using it. 3. Save the file.

Open the class in the project and look at it, you should see new definitions for notes row and textl (our new definitions) meaning we can now gain access to these from the our code.

0 0

Post a comment