Sabtu, 05 Oktober 2019

Aplikasi Dongeng Berbasis Android

A. Deskripsi.

Aplikasi Dongeng ini berisi kumpulan dongeng untuk anak sebelum tidur yang diakses dengan menggunakan HP android.

Perencanaan Program :

  1. Login NickName hanya mengambil nama untuk ditampilkan di halaman ListView Dongeng dan wajib diisi, jika tidak diisi akan muncul notifikasi permintaan NickName.
  2. Setelah Login berhasil akan dibawa ke halaman ListView Dongeng yang berisi kumpulan judul Dongeng.
  3. Untuk memilih Dongeng yang akan dibaca kita klik saja judulnya dan akan dibawa ke halaman isi text Dongeng.

B. Design, Source Code XML dan Source Code Java.

1. Halam Login

1.1. Design Graphic.



1.2. Surce Code XML


activity_main.xml
<?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"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="97dp"
        android:text="NickName Login"
        android:textAlignment="center"
        android:textSize="30sp"
        android:textStyle="normal|bold" />

    <EditText
        android:id="@+id/nickname"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="86dp"
        android:hint="Input Nickname"
        android:textAlignment="center"/>

    <Button
        android:id="@+id/btnLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/nickname"
        android:text="Log In"
        android:layout_marginRight="70dp"
        android:layout_marginLeft="70dp"/>

</RelativeLayout>


1.3. Source Code Java.


MainActivity.java
package com.example.hartono_161021450363;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    EditText user;
    Button login;

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

        user = (EditText) findViewById(R.id.nickname);
        login = (Button) findViewById(R.id.btnLogin);


        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String u,p;
                u = user.getText().toString();

                if(u.equals("")){
                    user.setError("Silakan isi NickName!!");

                }else{
                    Intent x = new Intent(MainActivity.this, ListDataDongeng.class);
                    x.putExtra("user", u);
                    startActivity(x);
                }

            }
        });
    }
}


2. Halaman ListView Dongeng.

2.1. Desing Graphic.



2.2. Source Code XML.

activity_list_data_dongeng.xml
<?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=".ListDataDongeng">

    <LinearLayout
        android:id="@+id/line1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/text1"
            android:textColorHighlight="@color/colorPrimaryDark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:textSize="16dp"/>
    </LinearLayout>

    <ListView
        android:id="@+id/listDongeng"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/line1"/>


</RelativeLayout>


2.3. Source Code Java.

ListDataDongeng.java
package com.example.hartono_161021450363;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class ListDataDongeng extends AppCompatActivity {

    TextView text;
    ListView listDongeng;
    //data yang akan dimasukkan ke listview
    private String [] dongeng = {"1. Cermin Ajaib","2. Pulau Matahari", "3. Singa dan Jakal yang cerdik", "4. Si Kura-kura yang sombong","5. Telur Emas"};
    //ArrayList untuk menampung data dongeng
    private ArrayList<String> data;

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

        text = (TextView) findViewById(R.id.text1);

        Intent y = getIntent();
        String user = y.getStringExtra("user");
        text.setText("Selamat Bercerita :  "+ user);

        listDongeng = findViewById(R.id.listDongeng);
        ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_single_choice,dongeng);
        listDongeng.setAdapter(adapter);


        listDongeng.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                int itemke=i;
                String itemText=(String) listDongeng.getItemAtPosition(i);
                Toast.makeText(getBaseContext(), "Anda Meng Klik " +itemText, Toast.LENGTH_SHORT).show();

                if (itemText.equals("1. Cermin Ajaib")){
                    Intent cerminajaib = new Intent(adapterView.getContext(),CerminAjaib.class);
                    startActivityForResult(cerminajaib, 0);
                }else if (itemText.equals("2. Pulau Matahari")){
                    Intent pulaumatahari = new Intent(adapterView.getContext(),PulauMatahari.class);
                    startActivityForResult(pulaumatahari, 0);
                }else if (itemText.equals("3. Singa dan Jakal yang cerdik")){
                    Intent singa = new Intent(adapterView.getContext(),SingaDanJakal.class);
                    startActivityForResult(singa, 0);
                }else if (itemText.equals("4. Si Kura-kura yang sombong")){
                    Intent kura = new Intent(adapterView.getContext(),KuraKura.class);
                    startActivityForResult(kura, 0);
                }else if (itemText.equals("5. Telur Emas")){
                    Intent telur = new Intent(adapterView.getContext(),TelurEmas.class);
                    startActivityForResult(telur, 0);
                }
            }
        });
    }
}



3. Halaman isi Dongeng.

3.1. Design Graphic.

Pada halaman isi Dongeng ini kita buat sebanyak judul Dongeng yang terdaftar di ListView. Jadi setiap judul memiliki satu halaman sendiri. berikut contoh salah satu halamannya :



3.2. Source Code XML.

a. Source Code XML Design.

activity_telur_emas.xml
<?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=".TelurEmas">

    <TextView
        android:id="@+id/textTelur"
        android:textColorHighlight="@color/colorPrimaryDark"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:textSize="14dp"
        android:textAlignment="gravity"
        android:text="@string/telur"/>


</RelativeLayout>

b. Source Code XML String untuk menyimpan isi cerita yang nanti akan ditamplikan di TextView.

string.xml
<string name="telur">5. Telur Emas\n\n
Alkisah, ada seekor angsa yang dapat mengeluarkan sebutir telur emas setiap hari. Angsa itu dimiliki seorang petani dan istrinya. Mereka bisa hidup nyaman dan berkecukupan berkat telur tersebut.\n\n

Kenyamanan ini berlangsung cukup lama. Namun pada suatu hari, tiba-tiba saja terbersit ide di benak petani tersebut. “Kenapa aku harus mendapatkan satu telur per hari? Kenapa tidak kuambil semuanya sekaligus dan jadi kaya raya?” pikirnya.\n\n

Istrinya ternyata setuju dengan ide tersebut. Mereka pun menyembelih si angsa dan membelah perutnya. Alangkah terkejutnya mereka ketika melihat perut tersebut hanya berisi daging dan darah. Tak ada telur sama sekali, apalagi emas.\n\n

Mereka pun menangis sejadi-jadinya. Tak ada sumber penghasilan tetap yang bisa mereka andalkan lagi. Mereka harus bekerja keras untuk menyambung hidup esok hari.</string>

String.xml berada pada res/layout/values/string.xml.


3.3. Source Code Java.

TelurEmas.java

package com.example.hartono_161021450363;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

public class TelurEmas extends AppCompatActivity {

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

        TextView tv = (TextView) findViewById(R.id.textTelur);
        tv.setMovementMethod(new ScrollingMovementMethod());
    }
}



C. Running Test.


Setelah semua source code dibuat saatnya kita test aplikasi tersebut, dan berikut hasilnya :

1. Halaman Login.


Jika Login NickName tidak diisi



2. Setelah NickName diisi akan menuju halaman ListView Dongeng.



3. Setelah halaman ListView Dongeng terbuka, kita bisa pilih dongeng mana yang akan dibuka







Demikian pembuatan Aplikasi Dongeng Berbasis Android semoga bermanfaat untuk pembelajaran android.







Minggu, 22 September 2019

Calculator Mbak Anna Berbasis Android

Calculator Mbak Anna ini adalah alat hitung sederhana berbasis Android untuk memudahkan dalam transaksi penghitungan pembayaran dan pengembalian uang kepada pelanggan yang selalu ramai padat dikunjungi oleh Mahasiswa/Mahasiswi Eresha terutama Kelas Reg. C di hari Sabtu. Maka dari itu terpikirlah ide untuk memecahkan masalah sederhana tersebut.

Berikut banner menu Warung Mbak Anna :

Gb.0 Menu Mbak Anna

Dari daftar menu di atas akan saya buat Calculator Mbak Anna dengan tampilan yang masih sederhana tapi dengan fungsi yang power full, berikut tampilan yang akan saya buat dan nantinya saya sertakan code programnya hingga semua berjalan seperti yang saya harapkan :

Gb.1. Tampilan Menu Utama

Gb.2. Tampilan Menu Ke-2


Untuk yang mau belajar pemrograman android siapkan dulu alat kerjanya :
1. Laptop/Notebook Minimal RAM 4GB (Emulator pake HP Android langsung).
2. Software Android Studio terbaru.
3. Internet dengan kecepatan yang bagus(Banyak download dan mencari referensi code program).
4. Niat untuk belajar Android Studio.


A. Deskripsi Aplikasi

  1. Aplikasi berisi nama Paket Menu dengan harga yang di setting sebelumnya di dalam code program java.
  2. Jumlah order menggunakan fungsi Increment dan Decrement yang nantinya akan di tampilkan di TextView order.
  3. Sub Total dari hasil perkalian jumlah order dengan harga paket.
  4. Total Bayar akan tampil otomatis setelah tombol +(Increment) atau -(Decrement) diklik. Jika nilai order = 0, maka tombol -(min) akan default Invisible.
  5. Setelah sesuai dengan yang diorder maka tombol Bayar diklik dan akan dibawa ke halaman Activity ke-2 (Pembayaran).
  6. Untuk tombol Reset berfungsi mereset semua nilai pada TextView menjadi 0 dan nilai variable pada program java menjadi 0. Setelah berhasil akan tampil notifikasi "Data berhasil di RESET"
  7. Pada tampilan Menu Ke-2 berisi Total Bayar,Peket Menu, Jml Order, Sub Total dimana nilainya berasal dari acitivity menu utama yang dikirim menggunakan Intent.
  8. EditText input pembayaran disetting harus memasukkan angka, menggunakan validasi form jika tidak sesuai akan memunculkan notifikasi.
  9. Fungsi tombol Bayar akan menjalankan validasi form, menghitung uang kembalian.

B. Source Code Aplikasi

Untuk mewujudkan deskripsi seperti pada point A, berikut Source Code nya :
  1. Source Code untuk tampilan Menu Utama (activity_main.xml).



Design activity_main

<?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">

<LinearLayout
    android:id="@+id/lineUtama"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button
        android:id="@+id/reset"
        android:layout_width="70dp"
        android:layout_height="30dp"
        android:layout_margin="5dp"
        android:background="#0AF314"
        android:text="Reset"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/totalBayar"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:text="TOTAL BAYAR"
        android:textAlignment="center"
        android:textColor="#3F51B5" />

    <Button
        android:id="@+id/bayarJml"
        android:layout_width="70dp"
        android:layout_height="30dp"
        android:layout_margin="5dp"
        android:background="#00B8D4"
        android:text="Bayar"
        android:textSize="10sp" />
</LinearLayout>


    <ScrollView
        android:layout_below="@+id/lineUtama"
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <LinearLayout
            android:id="@+id/line1"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp">

            <TextView
                android:id="@+id/paket1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="1. Paket 1 Rp.13.000,-(Nasi+Ayam Sayap+Lalap+Es Teh Manis)"
                android:textColor="#111111"
                android:textSize="12sp" />

            <Button
                android:id="@+id/kurang1"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:text="-"
                style="@style/Widget.AppCompat.Button.Borderless"
                android:textAlignment="center" />
            <TextView
                android:id="@+id/hasil1"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:text="0"
                android:textAlignment="center"/>
            <Button
                android:id="@+id/tambah1"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:text="+"
                style="@style/Widget.AppCompat.Button.Borderless"
                android:layout_marginRight="10dp"
                android:textAlignment="center"/>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/line2"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp">

            <TextView
                android:id="@+id/paket2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="2. Paket 2 Rp.16.000,-(Nasi+Ayam Paha+Lalap+Es Teh Manis)"
                android:textColor="#111111"
                android:textSize="12sp" />

            <Button
                android:id="@+id/kurang2"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:text="-"
                style="@style/Widget.AppCompat.Button.Borderless"
                android:textAlignment="center" />
            <TextView
                android:id="@+id/hasil2"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:text="0"
                android:textAlignment="center"/>
            <Button
                android:id="@+id/tambah2"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:text="+"
                style="@style/Widget.AppCompat.Button.Borderless"
                android:layout_marginRight="10dp"
                android:textAlignment="center"/>
        </LinearLayout>

            <LinearLayout
                android:id="@+id/line3"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="3. Paket 3 Rp.18.000,-(Nasi+Ayam Dada+Lalap+Es Teh Manis)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang3"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil3"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah3"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/line4"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket4"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"
                    android:layout_weight="1"
                    android:text="4. Paket 4 Rp.17.000,-(Nasi+Chicken Katsu+Salad+Es Teh Manis)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang4"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil4"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah4"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/line5"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="5. Paket 5 Rp.18.000,-(Nasi+Ayam Penyet+Lalap+Es Teh Manis)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang5"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil5"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah5"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/line6"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="6. Paket 6 Rp.16.000,-(Nasi+Teriyaki+Salad+Es Teh Manis)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang6"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil6"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah6"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/line7"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="7. Paket 7 Rp.12.000,-(Nasi Goreng)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang7"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil7"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah7"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/line8"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket8"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="8. Paket 8 Rp.12.000,-(Mie Orak-Arik)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang8"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil8"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah8"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/line9"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket9"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="9. Paket 9 Rp.10.000,-(Mendoan)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang9"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil9"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah9"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/line10"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket10"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="10. Paket 10 Rp.11.000,-(Nasi+Telor Dadar+Lalap+Es Teh Manis)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang10"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil10"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah10"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/line11"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp">

                <TextView
                    android:id="@+id/paket11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="11. Paket 11 Rp.5.000,-(Kopi,Es Cappucino Dll)"
                    android:textColor="#111111"
                    android:textSize="12sp" />

                <Button
                    android:id="@+id/kurang11"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="-"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:textAlignment="center" />
                <TextView
                    android:id="@+id/hasil11"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:text="0"
                    android:textAlignment="center"/>
                <Button
                    android:id="@+id/tambah11"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:text="+"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_marginRight="10dp"
                    android:textAlignment="center"/>
            </LinearLayout>


        </LinearLayout>

    </ScrollView>

</RelativeLayout>



  • Source Code untuk java Menu Utama (MainActivity.java).

  • package com.example.calcmbakanna;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Display;
    import android.view.Gravity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import java.text.NumberFormat;
    import java.util.Locale;
    
    public class MainActivity extends AppCompatActivity {
        TextView totalBayar,hasil1,hasil2,hasil3,hasil4,hasil5,hasil6,hasil7,hasil8,hasil9,hasil10,hasil11;
        EditText inputUang;
        Button reset,bayarJml,kurang1,kurang2,kurang3,kurang4,kurang5,kurang6,kurang7,kurang8,kurang9,
        kurang10,kurang11,tambah1,tambah2,tambah3,tambah4,tambah5,tambah6,tambah7,tambah8,tambah9,
                tambah10,tambah11;
        int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0,i10=0,i11=0;
        int paket1=13000,paket2=16000,paket3=18000,paket4=17000,paket5=18000,paket6=16000,paket7=
                12000,paket8=12000,paket9=10000,paket10=11000,paket11=5000;
        int jml1=0,jml2=0,jml3=0,jml4=0,jml5=0,jml6=0,jml7=0,jml8=0,jml9=0,jml10=0,jml11=0,jmlTotal=0;
        String sub1,sub2,sub3,sub4,sub5,sub6,sub7,sub8,sub9,sub10,sub11;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    
            totalBayar = (TextView) findViewById(R.id.totalBayar);
            hasil1 = (TextView) findViewById(R.id.hasil1);
            hasil2 = (TextView) findViewById(R.id.hasil2);
            hasil3 = (TextView) findViewById(R.id.hasil3);
            hasil4 = (TextView) findViewById(R.id.hasil4);
            hasil5 = (TextView) findViewById(R.id.hasil5);
            hasil6 = (TextView) findViewById(R.id.hasil6);
            hasil7 = (TextView) findViewById(R.id.hasil7);
            hasil8 = (TextView) findViewById(R.id.hasil8);
            hasil9 = (TextView) findViewById(R.id.hasil9);
            hasil10 = (TextView) findViewById(R.id.hasil10);
            hasil11 = (TextView) findViewById(R.id.hasil11);
            reset = (Button) findViewById(R.id.reset);
            bayarJml = (Button) findViewById(R.id.bayarJml);
            kurang1 = (Button) findViewById(R.id.kurang1);
            kurang2 = (Button) findViewById(R.id.kurang2);
            kurang3 = (Button) findViewById(R.id.kurang3);
            kurang4 = (Button) findViewById(R.id.kurang4);
            kurang5 = (Button) findViewById(R.id.kurang5);
            kurang6 = (Button) findViewById(R.id.kurang6);
            kurang7 = (Button) findViewById(R.id.kurang7);
            kurang8 = (Button) findViewById(R.id.kurang8);
            kurang9 = (Button) findViewById(R.id.kurang9);
            kurang10 = (Button) findViewById(R.id.kurang10);
            kurang11 = (Button) findViewById(R.id.kurang11);
            tambah1 = (Button) findViewById(R.id.tambah1);
            tambah2 = (Button) findViewById(R.id.tambah2);
            tambah3 = (Button) findViewById(R.id.tambah3);
            tambah4 = (Button) findViewById(R.id.tambah4);
            tambah5 = (Button) findViewById(R.id.tambah5);
            tambah6 = (Button) findViewById(R.id.tambah6);
            tambah7 = (Button) findViewById(R.id.tambah7);
            tambah8 = (Button) findViewById(R.id.tambah8);
            tambah9 = (Button) findViewById(R.id.tambah9);
            tambah10 = (Button) findViewById(R.id.tambah10);
            tambah11 = (Button) findViewById(R.id.tambah11);
            inVisible();
    
    
            kurang1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i1 = i1-1;
                    jml1 = i1 * paket1;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil1.setText(Integer.toString(i1));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i1<1){
                        kurang1.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i1 = i1+1;
                    jml1 = i1 * paket1;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil1.setText(Integer.toString(i1));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i1>0){
                        kurang1.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i2 = i2-1;
                    jml2 = i2 * paket2;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil2.setText(Integer.toString(i2));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i2<1){
                        kurang2.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i2 = i2+1;
                    jml2 = i2 * paket2;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil2.setText(Integer.toString(i2));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i2>0){
                        kurang2.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i3 = i3-1;
                    jml3 = i3 * paket3;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil3.setText(Integer.toString(i3));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i3<1){
                        kurang3.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i3 = i3+1;
                    jml3 = i3 * paket3;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil3.setText(Integer.toString(i3));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i3>0){
                        kurang3.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i4 = i4-1;
                    jml4 = i4 * paket4;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil4.setText(Integer.toString(i4));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i4<1){
                        kurang4.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i4 = i4+1;
                    jml4 = i4 * paket4;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil4.setText(Integer.toString(i4));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i4>0){
                        kurang4.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang5.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i5 = i5-1;
                    jml5 = i5 * paket5;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil5.setText(Integer.toString(i5));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i5<1){
                        kurang5.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah5.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i5 = i5+1;
                    jml5 = i5 * paket5;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil5.setText(Integer.toString(i5));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i5>0){
                        kurang5.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang6.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i6 = i6-1;
                    jml6 = i6 * paket6;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil6.setText(Integer.toString(i6));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i6<1){
                        kurang6.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah6.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i6 = i6+1;
                    jml6 = i6 * paket6;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil6.setText(Integer.toString(i6));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i6>0){
                        kurang6.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang7.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i7 = i7-1;
                    jml7 = i7 * paket7;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil7.setText(Integer.toString(i7));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i7<1){
                        kurang7.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah7.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i7 = i7+1;
                    jml7 = i7 * paket7;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil7.setText(Integer.toString(i7));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i7>0){
                        kurang7.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang8.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i8 = i8-1;
                    jml8 = i8 * paket8;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil8.setText(Integer.toString(i8));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i8<1){
                        kurang8.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah8.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i8 = i8+1;
                    jml8 = i8 * paket8;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil8.setText(Integer.toString(i8));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i8>0){
                        kurang8.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang9.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i9 = i9-1;
                    jml9 = i9 * paket9;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil9.setText(Integer.toString(i9));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i9<1){
                        kurang9.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah9.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i9 = i9+1;
                    jml9 = i9 * paket9;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil9.setText(Integer.toString(i9));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i9>0){
                        kurang9.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang10.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i10 = i10-1;
                    jml10 = i10 * paket10;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil10.setText(Integer.toString(i10));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i10<1){
                        kurang10.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah10.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i10 = i10+1;
                    jml10 = i10 * paket10;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil10.setText(Integer.toString(i10));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i10>0){
                        kurang10.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            kurang11.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i11 = i11-1;
                    jml11 = i11 * paket11;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil11.setText(Integer.toString(i11));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i11<1){
                        kurang11.setVisibility(View.INVISIBLE);
                    }
                }
            });
            tambah11.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i11 = i11+1;
                    jml11 = i11 * paket11;
                    jmlTotal = jml1+jml2+jml3+jml4+jml5+jml6+jml7+jml8+jml9+jml10+jml11;
                    hasil11.setText(Integer.toString(i11));
                    totalBayar.setText(NumberFormat.getNumberInstance(Locale.US).format(jmlTotal));
                    if(i11>0){
                        kurang11.setVisibility(View.VISIBLE);
                    }
                }
            });
    
            //membuat fungsi tombol Bayar
            bayarJml.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    sub1 = Integer.toString(jml1);
                    sub2 = Integer.toString(jml2);
                    sub3 = Integer.toString(jml3);
                    sub4 = Integer.toString(jml4);
                    sub5 = Integer.toString(jml5);
                    sub6 = Integer.toString(jml6);
                    sub7 = Integer.toString(jml7);
                    sub8 = Integer.toString(jml8);
                    sub9 = Integer.toString(jml9);
                    sub10 = Integer.toString(jml10);
                    sub11 = Integer.toString(jml11);
                    String jmltotal = Integer.toString(jmlTotal);
    
                    //Intent untuk mengirim parameter ke activity ke dua
                    Intent z = new Intent(MainActivity.this, Bayar.class);
                    z.putExtra("h1", hasil1.getText().toString());
                    z.putExtra("h2", hasil2.getText().toString());
                    z.putExtra("h3", hasil3.getText().toString());
                    z.putExtra("h4", hasil4.getText().toString());
                    z.putExtra("h5", hasil5.getText().toString());
                    z.putExtra("h6", hasil6.getText().toString());
                    z.putExtra("h7", hasil7.getText().toString());
                    z.putExtra("h8", hasil8.getText().toString());
                    z.putExtra("h9", hasil9.getText().toString());
                    z.putExtra("h10", hasil10.getText().toString());
                    z.putExtra("h11", hasil11.getText().toString());
                    z.putExtra("tb", jmltotal);
                    z.putExtra("suba", sub1);
                    z.putExtra("subb", sub2);
                    z.putExtra("subc", sub3);
                    z.putExtra("subd", sub4);
                    z.putExtra("sube", sub5);
                    z.putExtra("subf", sub6);
                    z.putExtra("subg", sub7);
                    z.putExtra("subh", sub8);
                    z.putExtra("subi", sub9);
                    z.putExtra("subj", sub10);
                    z.putExtra("subk", sub11);
                    startActivity(z);
                }
            });
    
            //Membuat fungsi tombol Reset
            reset.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
    
                    //Mengosongkan TextView dan membuat default nilai dari TextView
                    totalBayar.setText("0");
                    hasil1.setText("0");
                    hasil2.setText("0");
                    hasil3.setText("0");
                    hasil4.setText("0");
                    hasil5.setText("0");
                    hasil6.setText("0");
                    hasil7.setText("0");
                    hasil8.setText("0");
                    hasil9.setText("0");
                    hasil10.setText("0");
                    hasil11.setText("0");
                    i1 = 0;
                    i2 = 0;
                    i3 = 0;
                    i5 = 0;
                    i6 = 0;
                    i7 = 0;
                    i8 = 0;
                    i9 = 0;
                    i10 = 0;
                    i11 = 0;
                    jml1 = 0;
                    jml2 = 0;
                    jml3 = 0;
                    jml4 = 0;
                    jml5 = 0;
                    jml6 = 0;
                    jml7 = 0;
                    jml8 = 0;
                    jml9 = 0;
                    jml10 = 0;
                    jml11 = 0;
                    jmlTotal = 0;
                    inVisible();
                    //Notifikasi bahwa reset sudah berhasil
                    Toast tos = Toast.makeText(getApplicationContext()," Data Berhasil di RESET!!! ",
                            Toast.LENGTH_SHORT);
                    tos.setGravity(Gravity.CENTER, 0,0);
                    tos.show();
                }
            });
    
        }
        //set Button - ke mode Invisible
        private void inVisible(){
            kurang1.setVisibility(View.INVISIBLE);
            kurang2.setVisibility(View.INVISIBLE);
            kurang3.setVisibility(View.INVISIBLE);
            kurang4.setVisibility(View.INVISIBLE);
            kurang5.setVisibility(View.INVISIBLE);
            kurang6.setVisibility(View.INVISIBLE);
            kurang7.setVisibility(View.INVISIBLE);
            kurang8.setVisibility(View.INVISIBLE);
            kurang9.setVisibility(View.INVISIBLE);
            kurang10.setVisibility(View.INVISIBLE);
            kurang11.setVisibility(View.INVISIBLE);
        }
    }
    



  • Source Code untuk tampilan Menu Kedua (bayar.xml).


  • Design bayar


    <?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">
    
        <LinearLayout
            android:id="@+id/lineUtama"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end"
            android:orientation="vertical">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal">
    
                <TextView
                    android:id="@+id/textTotalBayar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="TOTAL BAYAR"
                    android:textColor="#3F51B5"
                    android:textSize="18sp"
                    android:layout_weight="1"/>
    
            <TextView
                android:id="@+id/totalBayar"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:layout_marginLeft="30dp"
                android:text="TOTAL BAYAR"
                android:textColor="#3F51B5"
                android:textSize="18sp" />
    
        </LinearLayout>
            <LinearLayout
                android:id="@+id/LineInputByr"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_marginTop="5dp">
    
            <EditText
                android:id="@+id/inputBayar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:hint="Input Pembayaran"
                android:inputType="number"
                android:textAlignment="viewEnd"
                android:textColor="#3F51B5"
                android:textSize="14sp" />
    
            <Button
                android:id="@+id/bayarBtn"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_gravity="right"
                android:text="Bayar"/>
    
            <TextView
                android:id="@+id/kembalian"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Kembalian"
                android:textAlignment="center"
                android:textColor="#3F51B5"
                android:textSize="20sp"
                android:layout_gravity="center" />
    
            </LinearLayout>
    
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/line0"
            android:layout_below="@id/lineUtama"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="20dp">
    
            <TextView
                android:id="@+id/namaPaket"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Nama Paket Menu"
                android:textColor="#111111"
                android:textSize="12sp" />
    
            <TextView
                android:id="@+id/orderNilai"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:text="Order"
                android:textColor="#111111"
                android:textAlignment="center"/>
    
            <TextView
                android:id="@+id/totalJudul"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sub Total"
                android:textColor="#111111"
                android:textAlignment="viewEnd"
                android:layout_gravity="end"/>
    
        </LinearLayout>
    
        <View
            android:layout_below="@id/line0"
            android:layout_margin="3dp"
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="#bbb"/>
    
    
        <ScrollView
            android:layout_below="@+id/line0"
            android:id="@+id/scroll"
            android:layout_marginTop="5dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
    
                <LinearLayout
                    android:id="@+id/line1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
    
                    <TextView
                        android:id="@+id/paket1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="1. Paket 1 Rp.13.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder1"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub1"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
    
                    <TextView
                        android:id="@+id/paket2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="2. Paket 2 Rp.16.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder2"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub2"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
    
                    <TextView
                        android:id="@+id/paket3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="3. Paket 3 Rp.18.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder3"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub3"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
    
                    <TextView
                        android:id="@+id/paket4"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="4. Paket 4 Rp.17.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder4"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub4"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
    
                    <TextView
                        android:id="@+id/paket5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="5. Paket 5 Rp.18.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder5"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub5"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line6"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
                    <TextView
                        android:id="@+id/paket6"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="6. Paket 6 Rp.16.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder6"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub6"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line7"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
                    <TextView
                        android:id="@+id/paket7"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="7. Paket 7 Rp.12.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder7"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub7"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line8"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
                    <TextView
                        android:id="@+id/paket8"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="8. Paket 8 Rp.12.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder8"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub8"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line9"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
                    <TextView
                        android:id="@+id/paket9"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="9. Paket 9 Rp.10.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder9"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub9"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line10"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
                    <TextView
                        android:id="@+id/paket10"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="10. Paket 10 Rp.11.000,-"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder10"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub10"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
                <LinearLayout
                    android:id="@+id/line11"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">
                    <TextView
                        android:id="@+id/paket11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="11. Paket 11 Rp.5.000,-(DRINK)"
                        android:textColor="#111111"
                        android:textSize="12sp" />
    
                    <TextView
                        android:id="@+id/jmlOrder11"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_marginRight="3dp"
                        android:text="00"
                        android:textAlignment="center"/>
    
                    <TextView
                        android:id="@+id/sub11"
                        android:layout_width="85dp"
                        android:layout_height="20dp"
                        android:text="000.000"
                        android:textAlignment="viewEnd"
                        android:layout_gravity="end"/>
                </LinearLayout>
    
            </LinearLayout>
    
        </ScrollView>
    
    
    
    </RelativeLayout>
    



  • Source Code untuk java Menu Kedua (Bayar.java).

  • package com.example.calcmbakanna;
    
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.PersistableBundle;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.view.Gravity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import androidx.annotation.Nullable;
    import androidx.appcompat.app.AppCompatActivity;
    
    import java.text.NumberFormat;
    import java.util.Locale;
    
    public class Bayar extends AppCompatActivity {
    
        EditText inputBayar;
        TextView totalBayar,kembalian;
        Button bayarBtn;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.bayar);
    
    
            inputBayar = (EditText) findViewById(R.id.inputBayar);
            kembalian = (TextView) findViewById(R.id.kembalian);
            totalBayar = (TextView) findViewById(R.id.totalBayar);
            bayarBtn = (Button) findViewById(R.id.bayarBtn);
            TextView jmlOrder1 = findViewById(R.id.jmlOrder1);
            TextView jmlOrder2 = findViewById(R.id.jmlOrder2);
            TextView jmlOrder3 = findViewById(R.id.jmlOrder3);
            TextView jmlOrder4 = findViewById(R.id.jmlOrder4);
            TextView jmlOrder5 = findViewById(R.id.jmlOrder5);
            TextView jmlOrder6 = findViewById(R.id.jmlOrder6);
            TextView jmlOrder7 = findViewById(R.id.jmlOrder7);
            TextView jmlOrder8 = findViewById(R.id.jmlOrder8);
            TextView jmlOrder9 = findViewById(R.id.jmlOrder9);
            TextView jmlOrder10 = findViewById(R.id.jmlOrder10);
            TextView jmlOrder11 = findViewById(R.id.jmlOrder11);
            TextView sub1 = findViewById(R.id.sub1);
            TextView sub2 = findViewById(R.id.sub2);
            TextView sub3 = findViewById(R.id.sub3);
            TextView sub4 = findViewById(R.id.sub4);
            TextView sub5 = findViewById(R.id.sub5);
            TextView sub6 = findViewById(R.id.sub6);
            TextView sub7 = findViewById(R.id.sub7);
            TextView sub8 = findViewById(R.id.sub8);
            TextView sub9 = findViewById(R.id.sub9);
            TextView sub10 = findViewById(R.id.sub10);
            TextView sub11 = findViewById(R.id.sub11);
    
    
            Intent x = getIntent();
            jmlOrder1.setText(x.getStringExtra("h1"));
            jmlOrder2.setText(x.getStringExtra("h2"));
            jmlOrder3.setText(x.getStringExtra("h3"));
            jmlOrder4.setText(x.getStringExtra("h4"));
            jmlOrder5.setText(x.getStringExtra("h5"));
            jmlOrder6.setText(x.getStringExtra("h6"));
            jmlOrder7.setText(x.getStringExtra("h7"));
            jmlOrder8.setText(x.getStringExtra("h8"));
            jmlOrder9.setText(x.getStringExtra("h9"));
            jmlOrder10.setText(x.getStringExtra("h10"));
            jmlOrder11.setText(x.getStringExtra("h11"));
            sub1.setText(x.getStringExtra("suba"));
            sub2.setText(x.getStringExtra("subb"));
            sub3.setText(x.getStringExtra("subc"));
            sub4.setText(x.getStringExtra("subd"));
            sub5.setText(x.getStringExtra("sube"));
            sub6.setText(x.getStringExtra("subf"));
            sub7.setText(x.getStringExtra("subg"));
            sub8.setText(x.getStringExtra("subh"));
            sub9.setText(x.getStringExtra("subi"));
            sub10.setText(x.getStringExtra("subj"));
            sub11.setText(x.getStringExtra("subk"));
            totalBayar.setText(x.getStringExtra("tb"));
    
    
    
            bayarBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
    
                    //Validasi form EditText untuk input pembayaran
                    if (inputBayar.getText().toString().trim().length() == 0) {
                        inputBayar.setError("Isi Dulu!!!");
                        return;
                    }
    
                    String in = inputBayar.getText().toString();
                    int input = Integer.parseInt(in);
                    String byr = totalBayar.getText().toString();
                    int bayar = Integer.parseInt(byr);
    
    
                    //validasi agar input pembayaran jumlahnya lebih besar dari pada total pembelian
                    if (input < bayar){
                        Toast t = Toast.makeText(getApplicationContext(),"Uangnya Kurang, Input Lagi!!! ",
                                Toast.LENGTH_SHORT);
                        t.setGravity(Gravity.CENTER, 0,0);
                        t.show();
                        inputBayar.setText("");
    
                    }else {
                        int kembali = input - bayar;
                        String kmb = NumberFormat.getNumberInstance(Locale.US).format(kembali);
                        kembalian.setText("Uang Kembalian = "+kmb);
                    }
                }
            });
        }
    }
    



  • Merubah code program pada AndroidManifest.xml untuk mendaftarkan activity ke dua agar bisa berjalan. Lihat pada bagian <activity android:name=".Bayar"/> Bayar adalah nama class java(Bayar.java).

  • <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.calcmbakanna">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".Bayar"/>
        </application>
    
    </manifest>
    



  • Merubah Tittle Applikasi silahkan buka pada res/values/String.xml seperti dibawah ini.

  • <resources>
        <string name="app_name">Hartono | 161021450363</string>
    </resources>
    

    C. Running Aplikasi

    Setelah selesai di tulis semua code programnya saatnya kita uji coba :


    1.  Pertama kita uji dengan memasukkan beberapa menu order dan lihat hasilnya.


    2. Selanjutnya Klik tombol Bayar dan lihat hasilnya akan dibawa ke halaman ke-2


    3. Akan kita test validasi form nya. Tanpa kita input nilai pembayaran dan langsung saja klik Bayar. Lihat hasilnya sebagai berikut :


    4. Selanjutnya kita cek validasi dengan nilai pembayaran kurang dari nilai Total Pembelian, silakan klik tombol Bayar dan lihat hasilnya



    5. Next, isi pada input pembayaran dengan nominal lebih besar dari Total Pembelian lalu klik tombol Bayar dan lihat hasilnya


    6. Semua berjalan sesuai skenario, untuk tombol kembali ke menu utama silakan klik tombol back pada perangkat HP android bawaan. 
    7. Untuk tombol RESET pada menu utama kita coba klik saja dan lihat hasilnya




    D. Saran dan Masukan

    Aplikasi sederhana ini masih bisa dikembangkan lebih menarik lagi misal bisa digunakan GridView untuk tampilan menu makanannya, penambahaan pop up, ataupun penggunaan cloud database untuk data yang lebih kompleks dan rumit.

    Sebagai bahan belajar, silakan dicopy dan dikembangkan sesuai keinginan. Jika ada saran dan masukan silakan tinggalkan komentar di kolom yang tersedia.





    Aplikasi Dongeng Berbasis Android

    A. Deskripsi. Aplikasi Dongeng ini berisi kumpulan dongeng untuk anak sebelum tidur yang diakses dengan menggunakan HP android. Perencan...