Skip to main content

Membuat Kamus dengan SQLite

Aplikasi ini dapat digunakan untuk keperluan kamus bahasa, kamus istilah, kamus teknik, kamus hukum, kamus kedokteran, kamus perpajakan, dan lainnya.


  1. Buatlah project baru dengan nama SqliteKamus, atau nama lain sesuai dengan keperluan Anda.
  2. Buatlah design layout untuk activity_main.xml seperti tampak pada gambar di bawah ini.
     3.  Berikut adalah skrip activity_main.xml apabila Anda kesulitan dalam membuat layout tersebut.
    xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@android:color/holo_orange_light"    android:orientation="vertical"    android:padding="10dp">
    
        <TextView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_gravity="center_horizontal"        android:paddingBottom="20dp"        android:text="Kamus Inggris Indonesia"        android:textAlignment="center"        android:textSize="24sp" />
    
        <TextView        android:id="@+id/TextView01"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Inggris :" />
    
        <EditText        android:id="@+id/txtInggris"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="" />
    
        <TextView        android:id="@+id/TextView03"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Indonesia :" />
    
        <EditText        android:id="@+id/txtIndonesia"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:editable="false"        android:text="" />
    
        <RelativeLayout        android:layout_width="match_parent"        android:layout_height="match_parent">
    
            <Button            android:id="@+id/btnTerjemah"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_alignParentBottom="true"            android:layout_alignParentLeft="true"            android:layout_alignParentStart="true"            android:background="@android:color/holo_orange_dark"            android:onClick="getTerjemahan"            android:text="Terjemahkan" />
    
            <ImageView            android:id="@+id/imageView"            android:layout_width="wrap_content"            android:layout_height="150dp"            android:layout_alignParentTop="true"            android:layout_centerHorizontal="true"            android:layout_marginTop="49dp"            app:srcCompat="@drawable/logo_ubj_256" />
        </RelativeLayout>
    
    
    </LinearLayout>
     
    5. Buka file MainActivity.java kemudian ganti isinya dengan skrip seperti berikut:
     
    package com.daniyusuf.sqlitekamus;
    
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.EditText;
    public class MainActivity extends AppCompatActivity {
        private SQLiteDatabase db = null;
        private Cursor kamusCursor = null;
        private EditText txtInggris;
        private EditText txtIndonesia;
        private DataKamus datakamus = null;
        public static final String INGGRIS = "inggris";
        public static final String INDONESIA = "indonesia";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            datakamus = new DataKamus(this);
            db = datakamus.getWritableDatabase();
            datakamus.createTable(db);
            datakamus.generateData(db);
            setContentView(R.layout.activity_main);
            txtInggris = (EditText) findViewById(R.id.txtInggris);
            txtIndonesia = (EditText) findViewById(R.id.txtIndonesia);
        }
        public void getTerjemahan(View view) {
            String result = "";
            String englishword = txtInggris.getText().toString();
            kamusCursor = db.rawQuery("SELECT ID, INGGRIS, INDONESIA "
                    + "FROM kamus where INGGRIS='" + englishword
                    + "' ORDER BY INGGRIS", null);
            if (kamusCursor.moveToFirst()) {
                result = kamusCursor.getString(2);
                for (; !kamusCursor.isAfterLast(); kamusCursor.moveToNext()) {
                    result = kamusCursor.getString(2);
                }
            }
            if (result.equals("")) {
                result = "Terjemahan Not Found";
            }
            txtIndonesia.setText(result);
        }
        @Override
        public void onDestroy() {
            super.onDestroy();
            kamusCursor.close();
            db.close();
        }
    } 
     
    6. Buat class baru dengan nama DataKamus.java, kemudian rubah isinya dengan skrip berikut ini.
     
    package com.daniyusuf.sqlitekamus;
    /**
     * Created by HP on 01/10/2018.
     */
    import android.content.ContentValues;
    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    public class DataKamus extends SQLiteOpenHelper {
        private static final String DATABASE_NAME = "dbkamus";
        public static final String INGGRIS= "inggris";
        public static final String INDONESIA = "indonesia";
        public DataKamus(Context context) {
            super(context, DATABASE_NAME, null, 1);
        }
        public void createTable(SQLiteDatabase db){
            db.execSQL("DROP TABLE IF EXISTS kamus");
            db.execSQL("CREATE TABLE if not exists kamus (id INTEGER PRIMARY KEY AUTOINCREMENT, inggris TEXT, indonesia TEXT);");
        }
        public void generateData(SQLiteDatabase db){
            ContentValues cv=new ContentValues();
            cv.put(INGGRIS, "run");
            cv.put(INDONESIA, "lari");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "walk");
            cv.put(INDONESIA, "jalan");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "read");
            cv.put(INDONESIA, "membaca");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "white");
            cv.put(INDONESIA, "putih");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "green");
            cv.put(INDONESIA, "hijau");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "blue");
            cv.put(INDONESIA, "biru");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "yellow");
            cv.put(INDONESIA, "kuning");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "black");
            cv.put(INDONESIA, "hitam");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "brown");
            cv.put(INDONESIA, "coklat");
            db.insert("kamus", INGGRIS, cv);
            cv.put(INGGRIS, "red");
            cv.put(INDONESIA, "merah");
            db.insert("kamus", INGGRIS, cv);
        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
        }
        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
        }
    } 
     
    7. Selanjutnya, jalankan aplikasi pada emulator android Anda.
    8. Tambahkan kosakata sesuai dengan keperluan Anda, aplikasi kamus ini juga dapat Anda gunakan untuk keperluan lain, misalnya kamus teknik, otomotif, kesehatan, dsb. 

    Comments

    Popular posts from this blog

    Program PHP sederhana untuk menghitung simulasi kredit

    Membuat Form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- body,td,th { font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; } --> </style></head> <?php $harga=$_GET['harga']; $dp=$harga*0.2; ?> <body> <H2>FORM SIMULASI KREDIT </H2> <br /> <form id="form1" name="form1" method="post" action="simulasi_proses1.php"> <table width="580" border="0" cellspacing="2" cellpadding="2"> <tr> <td>Harga Kendaraan </td>

    Android studio contoh penerapan looping

    Berikut adalah contoh penerapan looping pada android studio, program akan melakukan looping sebanyak 10 kali dan mencetak angka dari 1 sampai 11 . Buka dan edit file activity_main.xml seperti berikut: activity_main.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= "daniyusuf.com.contohlooping.MainActivity" > < TextView android :id= "@+id/txt_looping" android :layout_width= "match_parent" android :layout_height= "wrap_content" android :text= "Hello World!" app :layout_constraintBottom_toBottomOf= "parent"

    COMPONENT-LEVEL DESIGN

    Component-level design, atau juga dikenal dengan procedural design, baru ada setelah data, arsitektur dan rancangan antarmuka dibuat terlebih dahulu. Component-level design tujuannya adalah untuk menterjemahkan model design ke bentuk software yang akan dibuat. Namun dikarenakan abstraksi model design yang sudah ada relatif tinggi sedangkan abstraksi tingkat program operasionalnya rendah, maka proses penterjemahannya ini menjadi sebuah tantangan tersendiri. Menurut Edsgar Dijkstra, dalam perlkuliahannya mengatakan [DIJ72]: “Software ini berbeda dibanding dengan produk lain, dimana aturannya adalah semakin tinggi kualitas akan berdampak pada harga. Orang yang benar-benar ingin memperoleh software yang dapat diandalkan akan percaya bahwa mereka harus bisa menemukan suatu alat/cara untuk menghindari memulai suatu sistem dengan bug, dan hasilnya adalah, proses programming menjadi lebih murah . . . programmer efektif . . . tidak boleh menghabiskan waktunya untuk memperbaiki debugg—mereka se