This is the user interface now.
This is the main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned" />
</LinearLayout>
We shall change the caption of the button to add.
This is done by adding a new String to
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Dedicated to Hypatia of Alexandria</string>
<string name="app_name">HypatiaBasicAndroid</string>
<string name="buttoncaption">Add</string>
</resources>
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class HypatiaBasicAndroidActivity extends Activity {
/** Called when the activity is first created. */
EditText t1,t2,t3;
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button)findViewById(R.id.button1);
t1=(EditText)findViewById(R.id.editText1);
t2=(EditText)findViewById(R.id.editText2);
t3=(EditText)findViewById(R.id.editText3);
b.setOnClickListener(new ButtonHandler());
}
class ButtonHandler implements OnClickListener
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try
{
int a=Integer.parseInt("" + t1.getText());
int b=Integer.parseInt("" + t2.getText());
int sum=a+b;
t3.setText("" + sum);
}
catch (Exception ex) {
// TODO: handle exception
t3.setText(ex.getMessage());
}
}
}
}











