Last active
October 28, 2016 17:37
-
-
Save sendz/1e5b578b81a23e754c80d2120e22ef89 to your computer and use it in GitHub Desktop.
Hitung Luas Codes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/activity_main" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
tools:context="io.github.sendz.hitungluas.MainActivity"> | |
<EditText | |
android:id="@+id/edit_text_panjang" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:inputType="number" | |
android:hint="Panjang" /> | |
<EditText | |
android:id="@+id/edit_text_lebar" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_below="@+id/edit_text_panjang" | |
android:inputType="number" | |
android:hint="Lebar" /> | |
<Button | |
android:id="@+id/button_hitung" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_below="@id/edit_text_lebar" | |
android:text="Hitung"/> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.sendz.hitungluas; | |
import android.os.Bundle; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
public class MainActivity extends AppCompatActivity { | |
private int panjang; | |
private int lebar; | |
private EditText inputPanjang; | |
private EditText inputLebar; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
inputPanjang = (EditText) findViewById(R.id.edit_text_panjang); | |
inputLebar = (EditText) findViewById(R.id.edit_text_lebar); | |
Button reset = (Button) findViewById(R.id.button_hitung); | |
reset.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
panjang = Integer.valueOf(inputPanjang.getText().toString()); | |
lebar = Integer.valueOf(inputLebar.getText().toString()); | |
int luas = panjang * lebar; | |
new AlertDialog.Builder(MainActivity.this).setTitle("Luas").setMessage(String.valueOf(luas)).show(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment