- Create a new class file
- Declare that extends Activity
- Register it at AndroidManifest.xml
- Create a new XML file of type Layout
- For the Layout set some of this properties: Orientation, Background
- Create a TextView and set some of this properties: Text, Text size, Text style, gravity, Layout width
- Create an EditText and set some of this properties: Id, Hint, Layout gravity, Layout width
- Create a Button and set some of this properties: Id, Layout gravity, Text, On click
- Override method onCreate and inflate the Layout
- Add the method to receive the Click event and do something
AndroidManifest.xml (partial)
<activity
android:name=".uiBasics"
android:label="@string/uiBasics">
</activity>
android:name=".uiBasics"
android:label="@string/uiBasics">
</activity>
uibasics.java
package com.correa.android.tests.uibasics;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class uiBasics extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.uibasics);
}
public void onClickMyButton(View view) {
EditText textMyEditText;
textMyEditText =
(EditText) findViewById(R.id.MyEditText);
Toast.makeText(this, textMyEditText.getText(),
Toast.LENGTH_LONG).show();
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class uiBasics extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.uibasics);
}
public void onClickMyButton(View view) {
EditText textMyEditText;
textMyEditText =
(EditText) findViewById(R.id.MyEditText);
Toast.makeText(this, textMyEditText.getText(),
Toast.LENGTH_LONG).show();
}
}
uibasics.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#AA0000FF">
<TextView android:id="@+id/textView1"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_width="fill_parent"
android:text="@string/textTextView1"
android:textStyle="bold"
android:gravity="center">
</TextView>
<EditText android:layout_height="wrap_content"
android:hint="Type something here"
android:layout_gravity="center"
android:layout_width="250sp"
android:id="@+id/MyEditText">
</EditText>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Press Me!"
android:id="@+id/MyButton"
android:onClick="onClickMyButton">
</Button>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#AA0000FF">
<TextView android:id="@+id/textView1"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_width="fill_parent"
android:text="@string/textTextView1"
android:textStyle="bold"
android:gravity="center">
</TextView>
<EditText android:layout_height="wrap_content"
android:hint="Type something here"
android:layout_gravity="center"
android:layout_width="250sp"
android:id="@+id/MyEditText">
</EditText>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Press Me!"
android:id="@+id/MyButton"
android:onClick="onClickMyButton">
</Button>
</LinearLayout>