Saturday, 16 July 2016

Cara membuat aplikasi android kalkulator sederhana dengan Eclipse

·   11


Disini saya akan sharing bagaimana cara membuat aplikasi android kalkulator sederhana dengan menggunakan compiler Eclipse. Dibawah ini contoh desain aplikasi kalkulator sederhana.



Berikut langkah-langkahnya :

1.Pertama anda terlebih dahulu buka compiler eclipse.
2.Lalu buat project baru dengan cara click di pojok kiri atas File, New, Android Aplication Project.

3.Isi Aplication Name dengan kalkulator.

4.Pilih Minimum Requirement SDK terserah anda kalau disini saya memilih OS Jelly Bean.

5.Seteleh itu klik next.
6.Pada Create Activity pilih Blank Activity lalu click next dan finish.

7.Copy Program untuk xml nya dibawah ini.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    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=".MainActivity" >

    <EditText
        android:id="@+id/txtInputan1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Input angka" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/txtInputan2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Input angka" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btnKurang"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="actionKurang"
            android:text="-" />

        <Button
            android:id="@+id/btnKurang"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="actionTambah"
            android:text="+" />

        <Button
            android:id="@+id/btnKali"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="actionKali"
            android:text="x" />

        <Button
            android:id="@+id/btnBagi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="actionBagi"
            android:text=":" />

    </LinearLayout>

    <TextView
        android:id="@+id/textviewHasil"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hasil" />

</LinearLayout>


8.Langkah terakhir copy program dibawah ini pada MainActivity.

package com.kalkulator;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

EditText Inputan1, Inputan2;
TextView viewHasil;
double angka1, angka2, hasil;
String hasilakhir;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


}

public void actionKurang(View v){
EditText Inputan1 = (EditText) findViewById(R.id.txtInputan1);
    EditText Inputan2 = (EditText) findViewById(R.id.txtInputan2);
    viewHasil = (TextView) findViewById(R.id.textviewHasil);
   
   
    angka1 = Double.parseDouble(Inputan1.getText().toString());
    angka2 = Double.parseDouble(Inputan2.getText().toString());
   
    hasil = angka1 - angka2;
    hasilakhir = String.valueOf(hasil);
    viewHasil.setText(hasilakhir);
}

public void actionTambah(View v){
EditText Inputan1 = (EditText) findViewById(R.id.txtInputan1);
    EditText Inputan2 = (EditText) findViewById(R.id.txtInputan2);
    viewHasil = (TextView) findViewById(R.id.textviewHasil);
   
   
    angka1 = Double.parseDouble(Inputan1.getText().toString());
    angka2 = Double.parseDouble(Inputan2.getText().toString());
   
    hasil = angka1 + angka2;
    hasilakhir = String.valueOf(hasil);
    viewHasil.setText(hasilakhir);
}

public void actionKali(View v){
EditText Inputan1 = (EditText) findViewById(R.id.txtInputan1);
    EditText Inputan2 = (EditText) findViewById(R.id.txtInputan2);
    viewHasil = (TextView) findViewById(R.id.textviewHasil);
   
   
    angka1 = Double.parseDouble(Inputan1.getText().toString());
    angka2 = Double.parseDouble(Inputan2.getText().toString());
   
    hasil = angka1 * angka2;
    hasilakhir = String.valueOf(hasil);
    viewHasil.setText(hasilakhir);
}

public void actionBagi(View v){
EditText Inputan1 = (EditText) findViewById(R.id.txtInputan1);
    EditText Inputan2 = (EditText) findViewById(R.id.txtInputan2);
    viewHasil = (TextView) findViewById(R.id.textviewHasil);
   
   
    angka1 = Double.parseDouble(Inputan1.getText().toString());
    angka2 = Double.parseDouble(Inputan2.getText().toString());
   
    hasil = angka1 / angka2;
    hasilakhir = String.valueOf(hasil);
    viewHasil.setText(hasilakhir);
}
@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;
}

}


Subscribe to this Blog via Email :

11 comments

Write comments
Fery Nisar
AUTHOR
12 July 2016 at 01:31 delete

ribet jga ya :3 susah :3 tpi ttg saya bisa dapet uang banyak dri app andro jdi pengen coba (y) nice post

Reply
avatar
Khalil Muza
AUTHOR
14 July 2016 at 10:42 delete

wah agak membingungkan, tapi mantap gan, thanks for share

Reply
avatar
Unknown
AUTHOR
16 July 2016 at 09:00 delete

keren gan, ane padahal baru belajar tapi gak mudeng terus, nice info

Reply
avatar
NM Rosyiddin
AUTHOR
16 July 2016 at 11:32 delete

cocok buat project hhhh

Reply
avatar
Unknown
AUTHOR
16 July 2016 at 21:47 delete

Makasi infonya gan, dapat ilmu baru

Reply
avatar
arief budiman
AUTHOR
17 July 2016 at 01:55 delete

maaf gan skrng udah bisa

Reply
avatar
Unknown
AUTHOR
17 July 2016 at 08:47 delete

oke ijin baca" dlu bro .
iseng" bikiin walau sederhana tapi buatan sendiri pasti lebih bangga . hhe

Reply
avatar
17 July 2016 at 08:56 delete

keren gan tapi sedikit rumit :3

Reply
avatar