You are on page 1of 21

Karyawan.

xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="INPUT DATA KARYAWAN" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="64dp"
android:text="Nama Karyawan" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="54dp"
android:text="Nama Departemen" />

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_marginLeft="48dp"
android:layout_toRightOf="@+id/textView3"
android:ems="10" >

<requestFocus />
</EditText>

<Spinner
android:id="@+id/spinner"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/editText1" />

<Button
android:id="@+id/tambahkaryawan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/spinner"
android:layout_centerVertical="true"
android:text="SIMPAN" />

<HorizontalScrollView android:id="@+id/horizontalScrollView"
android:layout_width="match_parent" android:layout_height="wrap_content">
<ScrollView android:layout_width="wrap_content"
android:layout_height="match_parent" android:id="@+id/verticalScrollView">
</ScrollView>
</HorizontalScrollView>

<TableLayout
android:id="@+id/tablekaryawan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tambahkaryawan"
android:layout_marginTop="35dp" >
</TableLayout>

</RelativeLayout>

package com.example.inputdatadepartemen;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager.LayoutParams;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

SQLLiteHelper sqLiteHelper = new SQLLiteHelper(this);


TableLayout tabeldepartemen;
Button buttonTambahDepartemen;
Button hal2;
ArrayList<Button> buttonEdit = new ArrayList<Button>();
ArrayList<Button> buttonDelete = new ArrayList<Button>();

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

tabeldepartemen = (TableLayout) findViewById(R.id.tabledepartemen);


buttonTambahDepartemen= (Button) findViewById(R.id.buttonTambahdepartemen);
buttonTambahDepartemen.setOnClickListener(this);
pindahkaryawan();
TableRow barisTabel = new TableRow(this);
barisTabel.setBackgroundColor(Color.RED);

TextView viewHeaderId = new TextView(this);


TextView viewHeaderNama = new TextView(this);

TextView viewHeaderAction = new TextView(this);

viewHeaderId.setText("ID Departemen");
viewHeaderNama.setText("Nama");

viewHeaderAction.setText("Action");

viewHeaderId.setPadding(5, 1, 5, 1);
viewHeaderNama.setPadding(5, 1, 5, 1);
viewHeaderAction.setPadding(5, 1, 5, 1);

barisTabel.addView(viewHeaderId);
barisTabel.addView(viewHeaderNama);

barisTabel.addView(viewHeaderAction);

tabeldepartemen.addView(barisTabel, new
TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

ArrayList<HashMap<String, String>> arrayListdepartemen =


sqLiteHelper.tampil_semua_departemen();

if (arrayListdepartemen.size() > 0) {
for (int i = 0; i < arrayListdepartemen.size(); i++) {
// ambil masing-masing hasmap dari arrayListBiodata
HashMap<String, String> hashMapRecordDepartemen =
arrayListdepartemen.get(i);
// JSONObject jsonChildNode = arrayBiodata.getJSONObject(i);
String name = hashMapRecordDepartemen.get("nama");

String id = hashMapRecordDepartemen.get("id_departemen");

System.out.println("Nama :" + name);

System.out.println("ID :" + id);


barisTabel = new TableRow(this);

if (i % 2 == 0) {
barisTabel.setBackgroundColor(Color.LTGRAY);
}

TextView viewId = new TextView(this);


viewId.setText(id);
viewId.setPadding(5, 1, 5, 1);
barisTabel.addView(viewId);

TextView viewNama = new TextView(this);


viewNama.setText(name);
viewNama.setPadding(5, 1, 5, 1);
barisTabel.addView(viewNama);

buttonEdit.add(i, new Button(this));


buttonEdit.get(i).setId(Integer.parseInt(id));
buttonEdit.get(i).setTag("Edit");
buttonEdit.get(i).setText("Edit");
buttonEdit.get(i).setOnClickListener(this);
barisTabel.addView(buttonEdit.get(i));

buttonDelete.add(i, new Button(this));


buttonDelete.get(i).setId(Integer.parseInt(id));
buttonDelete.get(i).setTag("Delete");
buttonDelete.get(i).setText("Delete");
buttonDelete.get(i).setOnClickListener(this);
barisTabel.addView(buttonDelete.get(i));

tabeldepartemen.addView(barisTabel, new TableLayout.LayoutParams(


LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

}
}

}
public void pindahkaryawan() {

hal2= (Button)findViewById(R.id.hal2);
hal2.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new
Intent(MainActivity.this,Halaman_karyawan.class));
}
}
);}
public void onClick(View view) {

if (view.getId() == R.id.buttonTambahdepartemen) {
// Toast.makeText(MainActivity.this, "Button Tambah Data",
// Toast.LENGTH_SHORT).show();
tambahDepartemen();
} else {
/*
* Melakukan pengecekan pada data array, agar sesuai dengan index
* masing-masing button
*/
for (int i = 0; i < buttonEdit.size(); i++) {

/* jika yang diklik adalah button edit */


if (view.getId() == buttonEdit.get(i).getId()
&& view.getTag().toString().trim().equals("Edit")) {
// Toast.makeText(MainActivity.this, "Edit : " +
// buttonEdit.get(i).getId(), Toast.LENGTH_SHORT).show();
int id = buttonEdit.get(i).getId();
getDataByID(id);

} /* jika yang diklik adalah button delete */


else if (view.getId() == buttonDelete.get(i).getId()
&& view.getTag().toString().trim().equals("Delete")) {
// Toast.makeText(MainActivity.this, "Delete : " +
// buttonDelete.get(i).getId(), Toast.LENGTH_SHORT).show();
int id = buttonDelete.get(i).getId();
deletedepartemen(id);

}
}
}
}

public void deletedepartemen(int id) {


sqLiteHelper.hapus_departemen(id);

/* restart acrtivity */
finish();
startActivity(getIntent());

public void getDataByID(int id) {


String namaEdit = null;
HashMap<String, String> hashMapdepartemen =
sqLiteHelper.tampil_departemen_berdasarkan_id(id);

for (int i = 0; i < hashMapdepartemen.size(); i++) {


namaEdit = hashMapdepartemen.get("nama");

LinearLayout layoutInput = new LinearLayout(this);


layoutInput.setOrientation(LinearLayout.VERTICAL);
// buat id tersembunyi di alertbuilder
final TextView viewId = new TextView(this);
viewId.setText(String.valueOf(id));
viewId.setTextColor(Color.TRANSPARENT);
layoutInput.addView(viewId);

final EditText editNama = new EditText(this);


editNama.setText(namaEdit);
layoutInput.addView(editNama);

AlertDialog.Builder builderEditDepartemen = new AlertDialog.Builder(this);


builderEditDepartemen.setTitle("Update Departemen");
builderEditDepartemen.setView(layoutInput);
builderEditDepartemen.setPositiveButton("Update",new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String nama = editNama.getText().toString();

System.out.println("Nama : " + nama


);

sqLiteHelper.update_departemen(Integer.parseInt(viewId.getText().toString()),
editNama.getText().toString());

/* restart acrtivity */
finish();
startActivity(getIntent());
}
});

builderEditDepartemen.setNegativeButton("Cancel",new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builderEditDepartemen.show();

public void tambahDepartemen() {


/* layout akan ditampilkan pada AlertDialog */
LinearLayout layoutInput = new LinearLayout(this);
layoutInput.setOrientation(LinearLayout.VERTICAL);

final EditText editNama = new EditText(this);


editNama.setHint("Nama");
layoutInput.addView(editNama);

AlertDialog.Builder builderInsertDepartemen = new AlertDialog.Builder(this);


builderInsertDepartemen.setTitle("Insert Departemen");
builderInsertDepartemen.setView(layoutInput);
builderInsertDepartemen.setPositiveButton("Insert",new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String nama = editNama.getText().toString();

System.out.println("Nama : " + nama );

sqLiteHelper.tambah_departemen(nama, nama);
/* restart acrtivity */
finish();
startActivity(getIntent());
}
});

builderInsertDepartemen.setNegativeButton("Cancel",new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builderInsertDepartemen.show();
}
}

Karyawanactivity

package com.example.inputtabhost;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager.LayoutParams;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class KaryawanActivity extends Activity implements OnClickListener {


Spinner spinner;
String ss;
SQLLiteHelper sqLiteHelper = new SQLLiteHelper(this);
TableLayout tabelkaryawan;
Button tambahkaryawan;
ArrayList<Button> buttonEdit = new ArrayList<Button>();
ArrayList<Button> buttonDelete = new ArrayList<Button>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.karyawan);

tabelkaryawan = (TableLayout) findViewById(R.id.tablekaryawan);


tambahkaryawan= (Button) findViewById(R.id.tambahkaryawan);
tambahkaryawan.setOnClickListener(this);
spinner=(Spinner) findViewById(R.id.spinner);

ss = spinner.getSelectedItem().toString();
loadSpinnerData();
TableRow barisTabel = new TableRow(this);
barisTabel.setBackgroundColor(Color.RED);

TextView viewHeaderId = new TextView(this);


TextView viewHeaderNama_karyawan = new TextView(this);
Spinner viewHeaderNama = new Spinner(this);

TextView viewHeaderAction = new TextView(this);

viewHeaderId.setText("ID Karyawan");
viewHeaderNama_karyawan.setText("Nama Karyawan");
viewHeaderNama.getSelectedItem();
viewHeaderAction.setText("Action");

viewHeaderId.setPadding(5, 1, 5, 1);
viewHeaderNama_karyawan.setPadding(5,1,5,1);
viewHeaderNama.setPadding(5, 1, 5, 1);
viewHeaderAction.setPadding(5, 1, 5, 1);

barisTabel.addView(viewHeaderId);
barisTabel.addView(viewHeaderNama_karyawan);
barisTabel.addView(viewHeaderNama);

barisTabel.addView(viewHeaderAction);

tabelkaryawan.addView(barisTabel, new
TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

ArrayList<HashMap<String, String>> arrayListKaryawan =


sqLiteHelper.tampil_semua_karyawan();

if (arrayListKaryawan.size() > 0) {
for (int i = 0; i < arrayListKaryawan.size(); i++) {
// ambil masing-masing hasmap dari arrayListBiodata
HashMap<String, String> hashMapKaryawan = arrayListKaryawan.get(i);
// JSONObject jsonChildNode = arrayBiodata.getJSONObject(i);
String nama_karyawan = hashMapKaryawan.get("nama_karyawan");
String nama = hashMapKaryawan.get("nama");
String id = hashMapKaryawan.get("id_departemen");

System.out.println("Nama_Karyawan :" + nama_karyawan);


System.out.println("Nama :" + nama);
System.out.println("ID :" + id);

barisTabel = new TableRow(this);

if (i % 2 == 0) {
barisTabel.setBackgroundColor(Color.LTGRAY);
}

TextView viewId = new TextView(this);


viewId.setText(id);
viewId.setPadding(5, 1, 5, 1);
barisTabel.addView(viewId);

Spinner viewNama=new Spinner(this);


viewNama.getSelectedItem();

barisTabel.addView(viewNama);

TextView viewNama_karyawan = new TextView(this);


viewNama_karyawan.setText(nama_karyawan);
viewNama_karyawan.setPadding(5, 1, 5, 1);
barisTabel.addView(viewNama_karyawan);
buttonEdit.add(i, new Button(this));
buttonEdit.get(i).setId(Integer.parseInt(id));
buttonEdit.get(i).setTag("Edit");
buttonEdit.get(i).setText("Edit");
buttonEdit.get(i).setOnClickListener(this);
barisTabel.addView(buttonEdit.get(i));

buttonDelete.add(i, new Button(this));


buttonDelete.get(i).setId(Integer.parseInt(id));
buttonDelete.get(i).setTag("Delete");
buttonDelete.get(i).setText("Delete");
buttonDelete.get(i).setOnClickListener(this);
barisTabel.addView(buttonDelete.get(i));

tabelkaryawan.addView(barisTabel, new TableLayout.LayoutParams(


LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

}
}

public void onClick(View view) {

if (view.getId() == R.id.tambahkaryawan) {
// Toast.makeText(MainActivity.this, "Button Tambah Data",
// Toast.LENGTH_SHORT).show();
tambahkaryawan();
} else {
/*
* Melakukan pengecekan pada data array, agar sesuai dengan index
* masing-masing button
*/
for (int i = 0; i < buttonEdit.size(); i++) {

/* jika yang diklik adalah button edit */


if (view.getId() == buttonEdit.get(i).getId()
&& view.getTag().toString().trim().equals("Edit")) {
// Toast.makeText(MainActivity.this, "Edit : " +
// buttonEdit.get(i).getId(), Toast.LENGTH_SHORT).show();
int id = buttonEdit.get(i).getId();
getDataByID(id);

} /* jika yang diklik adalah button delete */


else if (view.getId() == buttonDelete.get(i).getId()
&& view.getTag().toString().trim().equals("Delete")) {
// Toast.makeText(MainActivity.this, "Delete : " +
// buttonDelete.get(i).getId(), Toast.LENGTH_SHORT).show();
int id = buttonDelete.get(i).getId();
deletedepartemen(id);

}
}
}
}

public void deletedepartemen(int id) {


sqLiteHelper.hapus_departemen(id);

/* restart acrtivity */
finish();
startActivity(getIntent());

public void getDataByID(int id) {


String namaEdit = null;
HashMap<String, String> hashMapdepartemen =
sqLiteHelper.tampil_departemen_berdasarkan_id(id);

for (int i = 0; i < hashMapdepartemen.size(); i++) {


namaEdit = hashMapdepartemen.get("nama");

LinearLayout layoutInput = new LinearLayout(this);


layoutInput.setOrientation(LinearLayout.VERTICAL);

// buat id tersembunyi di alertbuilder


final TextView viewId = new TextView(this);
viewId.setText(String.valueOf(id));
viewId.setTextColor(Color.TRANSPARENT);
layoutInput.addView(viewId);

final EditText editNama = new EditText(this);


editNama.setText(namaEdit);
layoutInput.addView(editNama);

AlertDialog.Builder builderEditDepartemen = new AlertDialog.Builder(this);


builderEditDepartemen.setTitle("Update Departemen");
builderEditDepartemen.setView(layoutInput);
builderEditDepartemen.setPositiveButton("Update",new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String nama = editNama.getText().toString();

System.out.println("Nama : " + nama


);

sqLiteHelper.update_departemen(Integer.parseInt(viewId.getText().toString()),
editNama.getText().toString());
/* restart acrtivity */
finish();
startActivity(getIntent());
}
});

builderEditDepartemen.setNegativeButton("Cancel",new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builderEditDepartemen.show();

public void tambahkaryawan() {


/* layout akan ditampilkan pada AlertDialog */
LinearLayout layoutInput = new LinearLayout(this);
layoutInput.setOrientation(LinearLayout.VERTICAL);

final EditText editNama_karyawan = new EditText(this);


editNama_karyawan.setHint("Nama_Karyawan");
layoutInput.addView(editNama_karyawan);
final Spinner editNama = new Spinner(this);
editNama.getSelectedItem();
layoutInput.addView(editNama);

AlertDialog.Builder builderInsertKaryawan = new AlertDialog.Builder(this);


builderInsertKaryawan.setTitle("Insert Karyawan");
builderInsertKaryawan.setView(layoutInput);
builderInsertKaryawan.setPositiveButton("Insert",new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String nama_karyawan =
editNama_karyawan.getText().toString();
String nama=editNama.getSelectedItem().toString();

System.out.println("Nama Karyawan: " + nama_karyawan );


System.out.println("Nama Departemen : " + nama);

sqLiteHelper.tambahkaryawan(nama_karyawan, nama_karyawan);
sqLiteHelper.tambahkaryawan(nama, nama);
/* restart acrtivity */
finish();
startActivity(getIntent());
}
});

builderInsertKaryawan.setNegativeButton("Cancel",new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builderInsertKaryawan.show();
}

private void loadSpinnerData() {


// database handler
SQLLiteHelper db = new SQLLiteHelper(getApplicationContext());

// Spinner Drop down elements


List<String> lables = db.getAllLabels();

// Creating adapter for spinner


ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, lables);

// Drop down layout style - list view with radio button


dataAdapter

.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

// attaching data adapter to spinner


spinner.setAdapter(dataAdapter);
}
}

Sqllitehelper

package com.example.inputtabhost;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;

import android.content.ContentValues;

import android.content.Context;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteOpenHelper;

public class SQLLiteHelper extends SQLiteOpenHelper {

private static final String nama_database = "db_karyawan";

private static final int versi_database = 1;

private static final String query_buat_tabel_departemen = "CREATE TABLE IF NOT EXISTS


departemen(id_departemen INTEGER PRIMARY KEY AUTOINCREMENT, nama TEXT)";

private static final String query_hapus_tabel_departemen = "DROP TABLE IF EXISTS


query_buat_tabel_departemen";

private static final String nama_tabel="departemen";

private static final String query_buat_tabel_kayawan = "CREATE TABLE IF NOT EXISTS


karyawan(id_karyawan INTEGER PRIMARY KEY AUTOINCREMENT, nama_karyawan TEXT, nama
TEXT)";

private static final String query_hapus_tabel_karyawan = "DROP TABLE IF EXISTS


query_buat_tabel_karyawan";

private static final String nama_tabel_karyawann="karyawan";

public SQLLiteHelper(Context context) {

super(context, nama_database, null, versi_database);

@Override

public void onCreate(SQLiteDatabase sqLiteDatabase) {

sqLiteDatabase.execSQL(query_buat_tabel_departemen);
System.out.println("tabel departemen sudah dibuat");

sqLiteDatabase.execSQL("tabel");

public void onCreate1(SQLiteDatabase sqLiteDatabase) {

sqLiteDatabase.execSQL(query_buat_tabel_kayawan);

System.out.println("tabel karyawan sudah dibuat");

sqLiteDatabase.execSQL("tabel");

@Override

public void onUpgrade(SQLiteDatabase database, int versi_lama, int versi_baru) {

database.execSQL(query_hapus_tabel_departemen);

onCreate(database);

public void onUpgrade1(SQLiteDatabase database, int versi_lama, int versi_baru) {

database.execSQL(query_hapus_tabel_karyawan);

onCreate(database);

public void tambah_departemen(String nama, String alamat) {

SQLiteDatabase database = this.getWritableDatabase();

ContentValues values = new ContentValues();

values.put("nama", nama);

database.insert("departemen", null, values);

database.close();

}
public void tambahkaryawan(String nama_karyawan, String nama) {

SQLiteDatabase database=this.getWritableDatabase();

ContentValues values=new ContentValues();

values.put("nama_karyawan",nama_karyawan);

values.put("nama", nama);

database.insert("karyawan",null, values);

database.close();

// TODO Auto-generated method stub

public ArrayList<HashMap<String, String>> tampil_semua_departemen() {

SQLiteDatabase database = this.getWritableDatabase();

// deklarasikan sebuah arraylist yang bisa menampung hashmap

ArrayList<HashMap<String, String>> arrayListDepartemen = new


ArrayList<HashMap<String, String>>();

Cursor cursor = database.rawQuery("SELECT * FROM departemen", null);

// kursor langsung diarkan ke posisi paling awal data pada tabel_biodata

if (cursor.moveToFirst()) {

do {

// deklarasikan sebuah hashmap, yang bisa menamp

HashMap<String, String> hashMapdepartemen = new HashMap<String,


String>();

// masukkan masing-masing field dari tabel_biodata ke dalamhashMapBiodata


// pastikan id_biodata, nama dan alamat sama persis dengan field yang ada
pada tabel_biodata

hashMapdepartemen.put("id_departemen", cursor.getString(0));

hashMapdepartemen.put("nama", cursor.getString(1));

// masukkan hashMapBiodata ke dalam arrayListBiodata

arrayListDepartemen.add(hashMapdepartemen);

} while (cursor.moveToNext());

return arrayListDepartemen;

public ArrayList<HashMap<String, String>> tampil_semua_karyawan() {

SQLiteDatabase database = this.getWritableDatabase();

// deklarasikan sebuah arraylist yang bisa menampung hashmap

ArrayList<HashMap<String, String>> arrayLisKaryawan = new


ArrayList<HashMap<String, String>>();

Cursor cursor = database.rawQuery("SELECT * FROM karyawan", null);

// kursor langsung diarkan ke posisi paling awal data pada tabel_biodata

if (cursor.moveToFirst()) {

do {

// deklarasikan sebuah hashmap, yang bisa menamp


HashMap<String, String> hashMapkaryawan = new HashMap<String, String>();

// masukkan masing-masing field dari tabel_biodata ke dalamhashMapBiodata

// pastikan id_biodata, nama dan alamat sama persis dengan field yang ada
pada tabel_biodata

hashMapkaryawan.put("id_karyawan", cursor.getString(0));

hashMapkaryawan.put("nama_karyawan", cursor.getString(1));

hashMapkaryawan.put("nama", cursor.getString(2));

// masukkan hashMapBiodata ke dalam arrayListBiodata

arrayLisKaryawan.add(hashMapkaryawan);

} while (cursor.moveToNext());

return arrayLisKaryawan;

public int update_departemen(int id, String nama) {

SQLiteDatabase database = this.getWritableDatabase();

ContentValues recordDepartemen = new ContentValues();

recordDepartemen.put("nama", nama);

return database.update("departemen", recordDepartemen, "id_departemen=" + id,


null);

}
public int update_karyawan(int id_karyawan, String nama_karyawan, String nama) {

SQLiteDatabase database = this.getWritableDatabase();

ContentValues recordKaryawan = new ContentValues();

recordKaryawan.put("nama_karayawan", nama_karyawan);

recordKaryawan.put("nama", nama);

return database.update("karyawan", recordKaryawan, "id_karyawan=" + id_karyawan,


null);

public void hapus_departemen(int id) {

SQLiteDatabase database = this.getWritableDatabase();

database.execSQL("DELETE FROM departemen WHERE id_departemen='" + id + "'");

database.close();

public void hapus_karyawan(int id_karyawan) {

SQLiteDatabase database = this.getWritableDatabase();

database.execSQL("DELETE FROM karyawan WHERE id_karyawan='" + id_karyawan +


"'");

database.close();

public HashMap<String, String> tampil_departemen_berdasarkan_id(int id) {

SQLiteDatabase database = this.getReadableDatabase();

HashMap<String, String> hashMapdepartemen = new HashMap<String, String>();

Cursor cursor = database.rawQuery("SELECT * FROM departemen WHERE id_departemen="


+ id + "", null);
if (cursor.moveToFirst()) {

do {

hashMapdepartemen.put("id_departemen", cursor.getString(0));

hashMapdepartemen.put("nama", cursor.getString(1));

} while (cursor.moveToNext());

return hashMapdepartemen;

public HashMap<String, String> tampil_karyawan_berdasarkan_id(int id_karyawan) {

SQLiteDatabase database = this.getReadableDatabase();

HashMap<String, String> hashMapkaryawan = new HashMap<String, String>();

Cursor cursor = database.rawQuery("SELECT * FROM karyawan WHERE id_karyawan=" +


id_karyawan + "", null);

if (cursor.moveToFirst()) {

do {

hashMapkaryawan.put("id_karyawan", cursor.getString(0));

hashMapkaryawan.put("nama_karyawan", cursor.getString(1));

hashMapkaryawan.put("nama", cursor.getString(3));

} while (cursor.moveToNext());

return hashMapkaryawan;

public List<String> getAllLabels(){

List<String> labels = new ArrayList<String>();


// Select All Query

String selectQuery = "SELECT * FROM " + nama_tabel;

SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list

if (cursor.moveToFirst()) {

do {

labels.add(cursor.getString(1));

} while (cursor.moveToNext());

// closing connection

cursor.close();

db.close();

// returning lables

return labels;