Aplikasi Data Kependudukan


Assalamualaikum Wr. Wb.

Balik lagi saya Andri Yuliyanto Mahasiswa STMIK Eresha ingin membuat aplikasi menggunakan Android Studio guna memenuhi syarat Ujian Akhir Semester di tahun 2020 ini.

1. Deskripsi Project

Di project ini saya membuat aplikasi sederhana tentang data kependudukan menggunakan menu login dan form pengisian data kependudukan yang disimpan ke databaseSQLite sebagai penyimpanan data dari akun yang akan masuk ke aplikasi.

2. Hasil foto dari Ujian tertulis dikampus

Foto dari Ujian tertulis



















3. Penjelasan dan Program Aplikasi
Disini saya langsung menjelaskan ke program yang saya buat, saya anggap kalian sudah mengetahui langkah awal pembuatannya atau bisa dicek diblog saya sebelumnya. Terima kasih😊

Dibawah ini adalah sebagai langkah-langkahnya:

a. Membuat Activty Login (activity_main.xml)

Screenshoot Form Login

 Source Code 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:layout_width="match_parent"    android:layout_height="match_parent"    android:layout_margin="16dp"
    >

    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_alignParentBottom="true"        android:background="#0091EA"        >
        <Button            android:text="LOGIN"            android:textColor="#FFF"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_alignParentBottom="true"            android:layout_centerHorizontal="true"            android:background="?android:attr/selectableItemBackground"            android:id="@+id/button2"            android:onClick="loginMasuk"            android:textStyle="normal|bold"/>
        />

    </LinearLayout>
    <EditText        android:id="@+id/edittext_username"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_above="@+id/edittext_password"        android:layout_alignParentStart="true"        android:layout_alignParentLeft="true"        android:layout_marginStart="3dp"        android:layout_marginLeft="3dp"        android:layout_marginBottom="9dp"        android:fontFamily="monospace"        android:hint="Username"        android:inputType="textCapWords"        android:textSize="30sp" />
    <EditText        android:id="@+id/edittext_password"        style="@style/AppTheme"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_alignParentStart="true"        android:layout_alignParentLeft="true"        android:layout_centerVertical="true"        android:layout_marginStart="-1dp"        android:layout_marginLeft="-1dp"        android:fontFamily="monospace"        android:hint="Password"        android:inputType="textPassword"        android:textSize="30sp" />
    <ImageView        android:id="@+id/imageView"        android:layout_width="140dp"        android:layout_height="119dp"        android:layout_alignParentStart="true"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true"        android:layout_marginStart="106dp"        android:layout_marginLeft="106dp"        android:layout_marginTop="86dp"
        tools:srcCompat="@tools:sample/avatars[0]" /></RelativeLayout>

b. Membuat Activity Form Pengisian Data (activity_formdata.xml)

Screenshoot Form Data

 Source Code activity_formdata.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"    android:theme="@android:style/Theme.NoTitleBar"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:background="#ddd"    android:padding="10dp"    tools:context="com.example.datart.Formdata">
    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:orientation="horizontal">
        <TextView            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="3"            android:text="Nama"            android:textColor="#000" />
        <EditText            android:id="@+id/editText_nama"            style="@android:style/Widget.Material.Light.EditText"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:ems="10"            android:hint="Nama"            android:inputType="textPersonName"            tools:targetApi="lollipop" />    </LinearLayout>
    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:orientation="horizontal">
        <TextView            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="3"            android:text="Jenis Kelamin"            android:textColor="#000" />
        <EditText            android:id="@+id/editText_JK"            style="@android:style/Widget.Material.Light.EditText"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:ems="10"            android:hint="Jenis Kelamin"            android:inputType="textPersonName" />    </LinearLayout>
    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:orientation="horizontal">
        <TextView            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="3"            android:text="Alamat"            android:textColor="#000" />
        <EditText            android:id="@+id/editText_almt"            style="@android:style/Widget.Material.Light.EditText"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:ems="10"            android:hint="Alamat"            android:inputType="textPersonName" />    </LinearLayout>
    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:orientation="horizontal">
        <TextView            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="3"            android:text="Nomor Rumah"            android:textColor="#000" />
        <EditText            android:id="@+id/editTextId"            style="@android:style/Widget.Material.Light.EditText"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:ems="10"            android:hint="Nomor Rumah"            android:inputType="textPersonName" />    </LinearLayout>
    <LinearLayout        android:layout_marginTop="20dp"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal">
        <Button            android:id="@+id/button_add"            style="@android:style/Widget.Material.Light.Button"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="#F9A825"            android:text="Simpan Data"            android:textAppearance="@android:style/TextAppearance.Material.Button"            android:textColor="@android:color/background_light"            tools:targetApi="lollipop" />
        <Button            android:id="@+id/button_view"            style="@android:style/Widget.Material.Light.Button"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="#4DD81B"            android:text="Lihat Semua"            android:textAppearance="@android:style/TextAppearance.Material.Button"            android:textColor="@android:color/background_light" />    </LinearLayout>
    <LinearLayout        android:layout_marginTop="20dp"        android:layout_width="match_parent"        android:orientation="horizontal"        android:layout_height="wrap_content">
        <Button            android:id="@+id/button_update"            style="@android:style/Widget.Material.Light.Button"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@color/colorAccent"            android:text="Perbarui"            android:textAppearance="@style/TextAppearance.AppCompat.Button"            android:textColor="@android:color/background_light" />
        <Button            android:id="@+id/button_delete"            style="@android:style/Widget.Material.Light.Button"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="#1565C0"            android:text="Hapus"            android:textAppearance="@style/TextAppearance.AppCompat.Button"            android:textColor="@android:color/background_light" />    </LinearLayout></LinearLayout>
Note: ini hanya sebuah contoh saya hanya memasukan beberapa text field di aplikasi ini
c. Source Code manifest android studio (AndroidManifest.xml)
Screenshoot Manifest android studio
 Source Code (AndroidManifest.xml)

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


Setelah semua file xml telah dibuat langkah selanjutnya yaitu membuat Activity Java.

1. LOGIN activity (MainActivity)


 
Screenshoot MainActivity (LOGIN)

Source Code MainActivity.java
 
package com.example.datart;

import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.EditText;import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
    EditText editText1 ,editText2; //Deklarasi object dari class EdiText    String text1 ,text2; //Deklarasi object string    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        getSupportActionBar().setTitle("Form Login");        getSupportActionBar().setSubtitle("Aplikasi Data Kependudukan");    }
    public void loginMasuk(View view) {
        //Method onClick pada Button
        editText1 = (EditText)findViewById(R.id.edittext_username);        editText2 = (EditText) findViewById(R.id.edittext_password);        text1 = editText1.getText().toString();        text2 = editText2.getText().toString();
        //Kondisi jika username dan password benar maka akan menampilkan pesan text toast        //Login sukses dan masuk ke activity 2        if ((text1.contains("Andriyuliyanto"))&&((text2.contains("Password")))) {
            Toast.makeText(this, "Login Sukses", Toast.LENGTH_SHORT).show();            Intent intent = new Intent(MainActivity.this, Formdata.class);            startActivity(intent);        }

        else if ((text1.matches("")||text2.matches("")))
          /*          Atau jika input text 1 dan text 2 kosong           */        {
            //Maka akan menampilkan pesan text toast            Toast.makeText(this, "Isikan Username dan Password", Toast.LENGTH_SHORT).show();
        }

        else {
            //jika kedua kondisi diatas tidak memenuhi
            Toast.makeText(this, "Login Gagal /Username Password Salah", Toast.LENGTH_SHORT).show();        }

    }



}

2. Form Data Activity (FormData)

Screenshoot Form Data Activity

Source Code FormData.java
 
package com.example.datart;

import android.app.AlertDialog;import android.database.Cursor;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class Formdata extends AppCompatActivity {

    DatabaseHelper myDb;
    EditText editNama,editJK,editAlmt,editTextId;
    Button btnAddData;
    Button btnViewAll;
    Button btnUpdate;
    Button btnDelete;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_formdata);
        myDb = new DatabaseHelper(this);
        editNama = (EditText)findViewById(R.id.editText_nama);
        editJK = (EditText)findViewById(R.id.editText_JK);
        editAlmt = (EditText)findViewById(R.id.editText_almt);
        editTextId = (EditText)findViewById(R.id.editTextId);
        btnAddData = (Button)findViewById(R.id.button_add);
        btnViewAll = (Button)findViewById(R.id.button_view);
        btnUpdate = (Button)findViewById(R.id.button_update);
        btnDelete = (Button)findViewById(R.id.button_delete);
        AddData();
        viewAll();
        UpdateData();
        deleteData();
    }



    //fungsi hapus
    public void deleteData() {

        btnDelete.setOnClickListener(

                new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        Integer deletedRows = myDb.deleteData(editTextId.getText().toString());
                        if (deletedRows > 0)

                            Toast.makeText(Formdata.this,"Data Telah Dihapus",Toast.LENGTH_LONG).show();
                        else
                            Toast.makeText(Formdata.this,"Data Gagal Dihapus!",Toast.LENGTH_LONG).show();
                    }

                }

        );
    }



    //fungsi update
    public void UpdateData() {

        btnUpdate.setOnClickListener(

                new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        boolean isUpdate = myDb.updateData(editTextId.getText().toString(),
                                editNama.getText().toString(),
                                editJK.getText().toString(),
                                editAlmt.getText().toString());
                        if(isUpdate == true)

                            Toast.makeText(Formdata.this,"Data Diperbarui",Toast.LENGTH_LONG).show();
                        else
                            Toast.makeText(Formdata.this,"Data Gagal Diperbarui",Toast.LENGTH_LONG).show();
                    }

                }

        );
    }



    //fungsi tambah
    public void AddData() {

        btnAddData.setOnClickListener(

                new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        boolean isInserted = myDb.insertData(editNama.getText().toString(),
                                editJK.getText().toString(),
                                editAlmt.getText().toString() );
                        if(isInserted == true)

                            Toast.makeText(Formdata.this,"Data Berhasil Disimpan",Toast.LENGTH_LONG).show();
                        else
                            Toast.makeText(Formdata.this,"Data Gagal Disimpan",Toast.LENGTH_LONG).show();
                    }

                }

        );
    }



    //fungsi menampilkan data
    public void viewAll() {

        btnViewAll.setOnClickListener(

                new View.OnClickListener(){

                    @Override
                    public void onClick(View v) {

                        Cursor res = myDb.getAllData();
                        if(res.getCount() == 0) {

                            // show message
                            showMessage("Error","Data Tidak Ditemukan");
                            return;
                        }



                        StringBuffer buffer = new StringBuffer();
                        while (res.moveToNext() ) {

                            buffer.append("No Rumah :"+ res.getString(0)+"\n");
                            buffer.append("Nama :"+ res.getString(1)+"\n");
                            buffer.append("Jenis Kelamin :"+ res.getString(2)+"\n");
                            buffer.append("Alamat :"+ res.getString(3)+"\n\n");
                        }



                        // show all data
                        showMessage("Data",buffer.toString());
                    }

                }

        );
    }



    //membuat alert dialog
    public void showMessage(String title, String Message){

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setTitle(title);
        builder.setMessage(Message);
        builder.show();
    }

}





3.  Tampilan Android Studio Database Helper.java

Screenshoot Database Helper.java



Source Code DatabaseHelper.java
 
package com.example.datart;
import android.content.ContentValues;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper{

    //nama database
    public static final String DATABASE_NAME = "Student.db";
    //nama table
    public static final String TABLE_NAME = "student_table";
    //versi database
    private static final int DATABASE_VERSION = 1;
    //table field
    public static final String COL_1 = "NoRumah";
    public static final String COL_2 = "Nama";
    public static final String COL_3 = "JenisKelamin";
    public static final String COL_4 = "Alamat";


    public DatabaseHelper(Context context) {

        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        SQLiteDatabase db = this.getWritableDatabase();
    }



    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(String.format("create table student_table(id integer primary key autoincrement,Nama text null,JenisKelamin text null,Alamat integer null);"));
    }



    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        db.execSQL("DROP TABLE IF EXISTS "+ TABLE_NAME);
        onCreate(db);
    }



    //metode untuk tambah data
    public boolean insertData(String Nama, String JenisKelamin, String Alamat) {

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(COL_2,Nama);
        contentValues.put(COL_3,JenisKelamin);
        contentValues.put(COL_4,Alamat);
        long result = db.insert(TABLE_NAME, null, contentValues);
        if(result == -1)

            return false;
        else
            return true;
    }



    //metode untuk mengambil data
    public Cursor getAllData() {

        SQLiteDatabase db = this.getWritableDatabase();
        Cursor res = db.rawQuery("select * from student_table", null);
        return res;
    }



    //metode untuk merubah data
    public boolean updateData(String NoRumah,String Nama,String JenisKelamin,String Alamat) {

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(COL_1,NoRumah);
        contentValues.put(COL_2,Nama);
        contentValues.put(COL_3,JenisKelamin);
        contentValues.put(COL_4,Alamat);
        db.update(TABLE_NAME,contentValues,"NoRumah = ?",new String[] {NoRumah});
        return true;
    }



    //metode untuk menghapus data
    public int deleteData (String NoRumah) {

        SQLiteDatabase db = this.getWritableDatabase();
        return db.delete(TABLE_NAME, "NoRumah = ?", new String[] {NoRumah});
    }

}



 Setelah semua selesai langkah selanjutnya mencoba hasil run dari aplikasi ini di hape android


Tampilan Form LOGIN



Tampilan Form LOGIN dan Use&Pass

Tampilan Form Pengisian Data


Tampilan Form Data dan Contoh Pengisiannya


Tampilan akhir pengisian data yang tersimpan di database

 Berikut adalah video dari aplikasi tersebut.




Sekian penjelasan aplikasi data kependudukan ini, mohon maaf jika dalam penjelasan banyak kekurangan dan mohon maaf jika project ini jauh dari kata sempurna. Sekali lagi saya ucapkan Terima kasih telah mampir ke blog saya😊😊





Komentar

Postingan populer dari blog ini

Aplikasi Brand Sepatu-Android Studio

UAS_BasisData II - Bon Pembelian SpareParts Motor dengan Koneksi SQL SERVER