Tabel 1: activity_main.xml activity_main.xml <EditText android:id="@+id/panjang" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="number" android:text="@string/input_panjang" > <requestFocus /> <EditText android:id="@+id/lebar" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10"
android:inputType="number" android:text="@string/input_lebar" /> <Button android:id="@+id/hitung" android:layout_width="284dp" android:layout_height="wrap_content" android:text="@string/button_hitung" /> <Button android:id="@+id/kosong" android:layout_width="280dp" android:layout_height="wrap_content" android:text="@string/kosong3" />
Tabel 2: strings.xml strings.xml <string <string <string <string <string <string <string <string <string <string <string <string <string <string <string <string
name="app_name">Yuhu name="action_settings">Settings name="hello_world">Hello world! name="panjang">Panjang name="input_panjang"> name="lebar">Lebar name="input_lebar"> name="button_hitung">Hitung name="welcome">Selamat Datang name="ahaha">Menghitung Luas Persegi name="kosong"> name="kosong2"> name="luas">Luas Persegi: name="kosong3">Kosongkan name="title_activity_oyeah">Oyeah name="luas2">
Tabel 3: MainActivity.java MainActivity.java package com.example.yuhu;
import import import import import import import
android.os.Bundle; android.app.Activity; android.view.Menu; android.view.View; android.widget.Button; android.widget.EditText; android.widget.TextView;
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final final final final final
EditText panjang=(EditText) findViewById(R.id.panjang); EditText lebar=(EditText) findViewById(R.id.lebar); Button hitung=(Button) findViewById(R.id.hitung); Button kosong=(Button) findViewById(R.id.kosong); TextView hasil=(TextView) findViewById(R.id.luas);
hitung.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int varPanjang=Integer.parseInt(panjang.getText().toString()); int varLebar=Integer.parseInt(lebar.getText().toString()); int luas=varPanjang*varLebar; hasil.setText("Luas Persegi: "+luas); } }); kosong.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { panjang.setText(null); lebar.setText(null); hasil.setText("Luas Persegi: "); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }