0% found this document useful (0 votes)
38 views

Mainactivity - Java: Public Void Int

The document contains code for a simple Android application that performs basic mathematical operations. It includes the MainActivity Java code which handles button clicks and calculations. It also includes the Activity_main XML layout file which defines the user interface with text views, edit texts, and buttons. Finally, it includes the Strings XML file which defines all the text labels and strings used in the application.

Uploaded by

Ibnu Kamajaya
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Mainactivity - Java: Public Void Int

The document contains code for a simple Android application that performs basic mathematical operations. It includes the MainActivity Java code which handles button clicks and calculations. It also includes the Activity_main XML layout file which defines the user interface with text views, edit texts, and buttons. Finally, it includes the Strings XML file which defines all the text labels and strings used in the application.

Uploaded by

Ibnu Kamajaya
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. MainActivity.

java

public void doClick(int id)


{
String s="";
int
a=Integer.parseInt((EditText)findViewById(R.id.txta).getText().toString(
));
int
b=Integer.parseInt((EditText)findViewById(R.id.txtB).getText().toString(
));
String t="";
switch(id)
{
case R.id.btnAdditional:
a=compute(a, b, Operator.ADD);
t="+";
break;
case R.id.btnDivition:
a=compute(a, b, Operator.DIV);
2. Activity_main.xml
<?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" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/strA"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/txta"
android:layout_width="82dp"
android:layout_height="wrap_content"
android:ems="10" >

<requestFocus />
</EditText>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/strB"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/txtB"
android:layout_width="81dp"
android:layout_height="wrap_content"
android:ems="10" />

<Button
android:id="@+id/btnAdditional"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strAditional" />

<Button
android:id="@+id/btnSubstraction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strSubstraction" />

<Button
android:id="@+id/btnMutiplication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strMutiplication" />

<Button
android:id="@+id/btnDivition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strDivition" />

<TextView
android:id="@+id/lblResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/strResult"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/txtResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />

<Button
android:id="@+id/btnClose1S"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/strClose"
android:onClick="doCloseApplication"
/>

</LinearLayout>

3. String.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Vd3</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="hello">Simple Math Application!</string>
<string name="strA">A=</string>
<string name="strB">B=</string>
<string name="strResult">Result: A+B=</string>
<string name="strAditional">A+B</string>
<string name="strSubstraction">A-B</string>
<string name="strMutiplication">A*B</string>
<string name="strDivition">A/B</string>
<string name="strClose">Close Application</string>
</resources>

You might also like