Haloo gays disini saya akan memberikan bagaimana cara
membuat aplikasi berbasis android,
1. klik File maka akan
muncul tampilan sebagai berikut

2. Setelah itu pilih Empty Activity akan muncul sebagai
berikut dan beri nama sesuai yg diinginkan

3 maka setelah itu tampilan akan seperti berikut

4. setelah itu kita melakukan codingan di activity_main.xml

Berikut codingannya
<?xml
version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp"
android:orientation="vertical"
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="#265"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/namapelanggan"
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="Judul Ebook : "
android:textStyle="bold"
android:textColor="#265"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/namabarang"
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 Beli: "
android:textStyle="bold"
android:textColor="#265"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/jumlahbeli"
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="#265"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/harga"
android:text=""
android:inputType="number"
android:layout_marginBottom="8dp" />
</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="#024"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/uangbayar"
android:text=""
android:inputType="number"/>
</LinearLayout>
<Button
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tombol1"
android:text="PROSES"
android:background="#5000"
android:textStyle="bold"
android:textColor="#265"
android:layout_marginBottom="8dp" />
<TextView
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Belanja "
android:textColor="#265"
android:id="@+id/totalbelanja"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginBottom="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Uang Kembali "
android:textColor="#265"
android:id="@+id/uangkembali"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bonus"
android:textColor="#265"
android:id="@+id/bonus"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Keterangan "
android:textColor="#265"
android:id="@+id/keterangan"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginBottom="8dp"/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/tombol2"
android:text="RESET DATA"
android:background="#5000"
android:textStyle="bold"
android:textColor="#265"/>
<Button
android:layout_width="200dp"
android:layout_marginLeft="20dp"
android:layout_height="wrap_content"
android:id="@+id/tombol3"
android:text="KELUAR"
android:background="#5000"
android:textColor="#265"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp"
android:orientation="vertical"
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="#265"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/namapelanggan"
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="Judul Ebook : "
android:textStyle="bold"
android:textColor="#265"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/namabarang"
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 Beli: "
android:textStyle="bold"
android:textColor="#265"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/jumlahbeli"
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="#265"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/harga"
android:text=""
android:inputType="number"
android:layout_marginBottom="8dp" />
</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="#024"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/uangbayar"
android:text=""
android:inputType="number"/>
</LinearLayout>
<Button
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tombol1"
android:text="PROSES"
android:background="#5000"
android:textStyle="bold"
android:textColor="#265"
android:layout_marginBottom="8dp" />
<TextView
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Belanja "
android:textColor="#265"
android:id="@+id/totalbelanja"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginBottom="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Uang Kembali "
android:textColor="#265"
android:id="@+id/uangkembali"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bonus"
android:textColor="#265"
android:id="@+id/bonus"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Keterangan "
android:textColor="#265"
android:id="@+id/keterangan"
android:textStyle="bold"
android:textSize="18dp"
android:layout_marginBottom="8dp"/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/tombol2"
android:text="RESET DATA"
android:background="#5000"
android:textStyle="bold"
android:textColor="#265"/>
<Button
android:layout_width="200dp"
android:layout_marginLeft="20dp"
android:layout_height="wrap_content"
android:id="@+id/tombol3"
android:text="KELUAR"
android:background="#5000"
android:textColor="#265"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Jika sudah kita lanjut codding di main activity untuk system
penarikan
package com.example.rusdi161021450471 import android.support.v4.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 edtnamapel, edtnamabar, edtjumlahbel, edtharga, edtuangbay; private Button btnproses; private Button btnhapus; private Button btnexit; private TextView txtnamapel; private TextView txtnamabar; private TextView txtjumlahbel; private TextView txtharga; private TextView txtuangbay; private TextView txtbonus; private TextView txttotalbelanja; private TextView txtuangkembali; private TextView txtketerangan; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportActionBar().setTitle("gudang sukses"); edtnamapel = (EditText) findViewById(R.id.namapelanggan); edtnamabar = (EditText) findViewById(R.id.namabarang); edtjumlahbel = (EditText) findViewById(R.id.jumlahbeli); edtharga = (EditText) findViewById(R.id.harga); edtuangbay = (EditText) findViewById(R.id.uangbayar); btnproses = (Button) findViewById(R.id.tombol1); btnhapus = (Button) findViewById(R.id.tombol2); btnexit = (Button) findViewById(R.id.tombol3); txtnamapel = (TextView) findViewById(R.id.namapelanggan); txtnamabar = (TextView) findViewById(R.id.namabarang); txtjumlahbel = (TextView) findViewById(R.id.jumlahbeli); txtharga = (TextView) findViewById(R.id.harga); txtuangbay = (TextView) findViewById(R.id.uangbayar); txtbonus = (TextView) findViewById(R.id.bonus); txttotalbelanja = (TextView) findViewById(R.id.totalbelanja); txtuangkembali = (TextView) findViewById(R.id.uangkembali); txtketerangan = (TextView) findViewById(R.id.keterangan); //memberikan action pada tombol proses btnproses.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String namapelanggan = edtnamapel.getText().toString().trim(); String namabarang = edtnamabar.getText().toString().trim(); String jumlahbeli = edtjumlahbel.getText().toString().trim(); String harga = edtharga.getText().toString().trim(); String uangbayar = edtuangbay.getText().toString().trim(); double jb = Double.parseDouble(jumlahbeli); double h = Double.parseDouble(harga); double ub = Double.parseDouble(uangbayar); double total = (jb * h); txttotalbelanja.setText("Total Belanja : " + total); //pemberian if dan else untuk aturan pemberian bonus if (total >=200000){ txtbonus.setText("Bonus : Mouse"); } else if (total >=50000){ txtbonus.setText("Bonus : Keyboard"); } else if (total >=40000){ txtbonus.setText("Bonus : Harddisk"); } else { txtbonus.setText("Bonus : Tidak Ada Bonus"); } double uangkembalian = (ub - total); if (ub < total){ txtketerangan.setText("Keterangan : uang bayar kurang Rp " + (-uangkembalian)); txtuangkembali.setText("Uang Kembali : Rp 0" ); }else{ txtketerangan.setText("Keterangan : Tunggu Kembalian"); txtuangkembali.setText("Uang Kembali : " + uangkembalian); } //memberikan action pada tombol reset data } }); btnhapus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { txtnamapel.setText(" "); txtnamabar.setText(" "); txttotalbelanja.setText(" Total Belanja : Rp 0"); txtharga.setText(" "); txtuangbay.setText(" "); txtuangkembali.setText("Uang Kembali : Rp 0"); txtbonus.setText("Bonus : - "); txtjumlahbel.setText(" "); txtketerangan.setText("Keterangan : - "); Toast.makeText(getApplicationContext(),"Data sudah direset", Toast.LENGTH_LONG).show(); // memberikan action pada tombol keluar } }); btnexit.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { moveTaskToBack(true); } }); } }
aplikasi pun bisa kita gunakan
Tidak ada komentar:
Posting Komentar