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:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/inputAngka1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Masukkan Angka 1(Hasil)" | |
/> | |
<EditText | |
android:id="@+id/editText1" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="0" | |
android:inputType="number" | |
android:layout_alignParentStart="true" | |
android:layout_marginTop="19dp" /> | |
<TextView | |
android:id="@+id/inputAngka2" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Masukkan Angka2" | |
android:layout_below="@+id/editText1" | |
android:layout_alignParentStart="true" | |
android:layout_marginTop="66dp" /> | |
<EditText | |
android:id="@+id/editText2" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="0" | |
android:inputType="number" | |
android:layout_below="@+id/editText1" | |
android:layout_alignParentStart="true" | |
android:layout_marginTop="107dp" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="19dp" | |
android:text="+" | |
android:id="@+id/buttonTambah" | |
android:layout_below="@+id/editText2" | |
android:layout_alignParentStart="true" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="-" | |
android:id="@+id/buttonKurang" | |
android:layout_above="@+id/buttonBagi" | |
android:layout_toEndOf="@+id/inputAngka2" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="x" | |
android:id="@+id/buttonKali" | |
android:layout_alignBaseline="@+id/buttonBagi" | |
android:layout_alignBottom="@+id/buttonBagi" | |
android:layout_alignParentStart="true" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text=":" | |
android:id="@+id/buttonBagi" | |
android:layout_below="@+id/buttonTambah" | |
android:layout_alignStart="@+id/buttonKurang" | |
android:layout_marginTop="45dp" /> | |
</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 com.blogspot.inwirawan.kalkulatorku; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
public class MainActivity extends AppCompatActivity { | |
EditText editText1, editText2; | |
Button buttonTambah; | |
Button buttonKurang; | |
Button buttonKali; | |
Button buttonBagi; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
editText1 = (EditText) findViewById(R.id.editText1); | |
editText2 = (EditText) findViewById(R.id.editText2); | |
buttonTambah = (Button) findViewById(R.id.buttonTambah); | |
buttonKurang = (Button) findViewById(R.id.buttonKurang); | |
buttonKali = (Button) findViewById(R.id.buttonKali); | |
buttonBagi = (Button) findViewById(R.id.buttonBagi); | |
buttonTambah.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
double a = Double.parseDouble(editText1.getText().toString()); | |
double b = Double.parseDouble(editText2.getText().toString()); | |
double result = a + b; | |
editText1.setText(Double.toString(result)); | |
} | |
}); | |
buttonKurang.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
double a = Double.parseDouble(editText1.getText().toString()); | |
double b = Double.parseDouble(editText2.getText().toString()); | |
double result = a - b; | |
editText1.setText(Double.toString(result)); | |
} | |
}); | |
buttonKali.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
double a = Double.parseDouble(editText1.getText().toString()); | |
double b = Double.parseDouble(editText2.getText().toString()); | |
double result = a * b; | |
editText1.setText(Double.toString(result)); | |
} | |
}); | |
buttonBagi.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
double a = Double.parseDouble(editText1.getText().toString()); | |
double b = Double.parseDouble(editText2.getText().toString()); | |
double result = a / b; | |
editText1.setText(Double.toString(result)); | |
} | |
}); | |
} | |
} |
Langkah pertama :
1. Buka Android Studio :D
2. Setting nama aplikasi, level API, dan letak file
3. Buka activity_main.xml, dan copy code activity_main.xml
4. Lalu buka Main_Activity.java dan copy code.
5. Run di hp dan jangan lupa aktifkan USB Debugging
Screenshoot hasil aplikasi
1 komentar:
Write komentarTest
ReplyEmoticonEmoticon