TUTORIAL MEMBUAT APLIKASI PENJUALAN MENGGUNAKAN ANDRIOD STUDIO

1. Deskrisi singkat aplikasi
      Kali ini kita akan belajar membuat aplikasi menggunakan andriod studio.
yang hasilnya akan seperti ini;

2. Buat Project Baru


Buka android studio > buat project baru dengan cara klik create new project > beri nama project “penjualan” (disesuaikan)  > tentukan target sdk nya> pilih empty activity > lanjutkan seperti di bawah ini;.
buatlah nama projec lalu simpan, kemudian pilih API level nya lalu klik FINIS.

3. Buat Layout

Jika workspace android studio sudah terbuka klik activity_main.xml. Disini kita akan membuat layout aplikasi dengan menggunakan Linearlayout dan  beberapa widget :
  • ScrollView
  • TextView
  • Button
  • EditText
lalu buat kode-kode xmlnya sebagai berikut :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:orientation="vertical"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Pembeli :"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nama_pelanggan"
android:text=""/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Barang :"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nama_barang"
android:text=""/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jumlah Barang :"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/jml_barang"
android:text=""
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Harga : Rp"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/harga_barang"
android:text=""
android:inputType="number"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Uang Bayar : Rp"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/jml_uang"
android:text=""
android:inputType="number"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:id="@+id/proses"
android:text="PROSES"
android:background="@color/colorAccent"
android:textColor="#ffffffff"
android:textStyle="bold"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Total Semua :"
android:textColor="@color/colorPrimary"
android:id="@+id/total"
android:textStyle="bold"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Uang Kembali :"
android:textColor="@color/colorPrimary"
android:id="@+id/kembalian"
android:textStyle="bold"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Bonus Belanja :"
android:textColor="@color/colorPrimary"
android:id="@+id/bonus"
android:textStyle="bold"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Keterangan :"
android:textColor="@color/colorPrimary"
android:id="@+id/keterangan"
android:textStyle="bold"
android:layout_marginBottom="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/reset"
android:text="Hapus"
android:layout_weight="1"
android:layout_margin="5dp"
android:background="@color/colorAccent"
android:textStyle="bold"
android:textColor="#ffffffff"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/exit"
android:text="Keluar"
android:layout_weight="1"
android:layout_margin="5dp"
android:background="@color/colorAccent"
android:textStyle="bold"
android:textColor="#ffffffff"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Setelah selesai maka akan tampil seperti gambar di atas.
Selanjutnya berikan perintah pada textview, button, dan komponen lainnya menggunakan bahasa pemrograman java pada MainActivity.java. 
seperti di bawah ini;
package com.RenoUTS.aplikasipenjualan;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText editnamapel,editnamabar,
editjumlahbar, editharga, edituangbay;
private Button btnproses;
private Button btnhapus;
private Button btnexit;
private TextView txtnamapel;
private TextView txtnamabar;
private TextView txtjumlahbar;
private TextView txtharga;
private TextView txtuangbay;
private TextView txtbonus;
private TextView txttotalbelanja;
private TextView txtkembali;
private TextView txtketerangan;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle("Aplikasi Penjualan Barang");
editnamapel = (EditText)findViewById(R.id.nama_pelanggan);
editnamabar = (EditText)findViewById(R.id.nama_barang);
editjumlahbar = (EditText)findViewById(R.id.jml_barang);
editharga = (EditText)findViewById(R.id.harga_barang);
edituangbay = (EditText)findViewById(R.id.jml_uang);
btnproses = (Button)findViewById(R.id.proses);
btnhapus = (Button)findViewById(R.id.reset);
btnexit = (Button)findViewById(R.id.exit);
txtnamapel = (TextView)findViewById(R.id.nama_pelanggan);
txtnamabar = (TextView)findViewById(R.id.nama_barang);
txtjumlahbar = (TextView)findViewById(R.id.jml_barang);
txtharga = (TextView)findViewById(R.id.harga_barang);
txtuangbay = (TextView)findViewById(R.id.jml_uang);
txttotalbelanja = (TextView)findViewById(R.id.total);
txtkembali = (TextView)findViewById(R.id.kembalian);
txtketerangan = (TextView)findViewById(R.id.keterangan);
txtbonus = (TextView)findViewById(R.id.bonus);
btnproses.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String namapelanggan = editnamapel.getText().toString().trim();
String namabarang = editnamabar.getText().toString().trim();
String jumlahbarang = editjumlahbar.getText().toString().trim();
String hargabarang = editharga.getText().toString().trim();
String uangbayar = edituangbay.getText().toString().trim();
double jb = Double.parseDouble(jumlahbarang);
double h = Double.parseDouble(hargabarang);
double ub = Double.parseDouble(uangbayar);
double total = (jb*h);
txttotalbelanja.setText("Total Belanja : "+total);
if (total >= 200000){
txtbonus.setText("Bonus : Harddisk");
}
else if (total >= 50000){
txtbonus.setText("Bonus : Keyboard");
}
else if (total >= 40000){
txtbonus.setText("Bonus : Mouse");
}
else {
txtbonus.setText("Bonus : Tidak Ada Bonus");
}
double uangkembalian = (ub-total);
if (ub<total){
txtketerangan.setText("Keterangan : uang bayar kurang Rp."+(-uangkembalian));
txtkembali.setText("Uang Kembalian : Rp. 0");
}
else{
txtketerangan.setText("Keterangan : Tunggu Kembalian");
txtkembali.setText("Uang Kembalian : "+uangkembalian);
}
}
});
btnhapus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtnamapel.setText(" ");
txtnamabar.setText(" ");
txtjumlahbar.setText(" ");
txtharga.setText(" ");
txtuangbay.setText(" ");
txtkembali.setText("Uang Kembali : Rp. 0");
txtketerangan.setText("-");
txtbonus.setText("-");
txttotalbelanja.setText("Total Belanja : Rp 0");
Toast.makeText(getApplicationContext(),"Data sudah dihapus", Toast.LENGTH_LONG).show();
}
});
btnexit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
moveTaskToBack(true);
}
});
}
}

S
e
telah selesai maka silahkan coba untuk di Run. dan hasilnya akan seperti di bawah ini.



Sekian untuk kali ini, kurang lebihnya mohon maaf.
TERIMAKASIH







Komentar

Postingan populer dari blog ini