Android an open handset alliance project by k. Mahesh chandra



Download 276.25 Kb.
Page6/8
Date17.12.2020
Size276.25 Kb.
#55088
1   2   3   4   5   6   7   8
1 (1)
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.




Download 276.25 Kb.

Share with your friends:
1   2   3   4   5   6   7   8




The database is protected by copyright ©ininet.org 2024
send message

    Main page