Getting work done
The main functionality you'll use is the Activity.
You can lay out the display using code, but this is not recommended. Instead, it is best to create the layout in a separate layout XML file. This layout file creates UI components with IDs. In this case, the layout file is in res/layout/main.xml. We can put assign the objects IDs in the layout file like this:
android:id="@+id/password"
android:layout_width="164px"
android:layout_height="wrap_content"
android:padding="10px"
android:textSize="18sp"
android:password="true"
>
Then, the build.xml file's resource-src task uses the aapt program to generate a file called R.java. R contains references to all the objects with IDs in the layout file, so in R we have:
public final class R {
public static final class id {
public static final int password=0x7f04000a;
Now, within the activity, we can get the password field and read text from it as follows:
final EditText passwordField = (EditText) findViewById(R.id.password);
String password = passwordField.getText().toString();
It's different from how we think of Swing or web layouts. It's also better. Layout should not be in code. Swing and other systems are moving in this same direction.
Share with your friends: |