Sie sind auf Seite 1von 9

TUGAS 08

PEMROGRAMAN APLIKASI MOBILE

Disusun Oleh :
Nama : NUR ALINI
NIM : 182002
Kelas :A
Jurusan : Teknik Informatika
SEKOLAH TINGGI MANAJEMEN INFORMATIKA DAN KOMPUTER

STMIK DIPANEGARA MAKASSAR TAHUN AJARAN 2020/2021


 IDE/Project Android Studio

Tampil Form Login Tampil Form Utama


 Tampilan Data Berhasil Tersimpan

 Tampilan Data Berhasil Terupdate


 Tampilan Data Berhasil Terhapus

 Tampilan Daftar Mahasiswa


 Listing InputActivity.java

package com.example.nuralini_182002_a;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.content.Context;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class InputActivity extends AppCompatActivity {


Button btnSimpan, btnsearch,btnedit,btnhapus;
EditText tNim, tNama, tAlamat, tTlp, tTmptlah, tTgllahir;
RadioGroup radioGroup;
RadioButton selectedRadioButton;
CheckBox cb1, cb2, cb3, cb4, cb5, cb6;

SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input);
db = openOrCreateDatabase("NURALINI_182002_A", Context.MODE_PRIVATE,
null);
db.execSQL("CREATE TABLE IF NOT EXISTS tbl_biodata(nim VARCHAR PRIMARY
KEY,nama VARCHAR,alamat VARCHAR,jk VARCHAR,tlp VARCHAR,tmptlah VARCHAR,tgllahir
VARCHAR,hobby VARCHAR);");

tNim = findViewById(R.id.nim);
tNama = findViewById(R.id.nama);
tAlamat = findViewById(R.id.alamat);
tTlp = findViewById(R.id.tlp);
tTmptlah = findViewById(R.id.tmptlah);
tTgllahir = findViewById(R.id.tgllahir);
btnedit = findViewById(R.id.btnedit);
btnhapus = findViewById(R.id.btnhapus);
btnsearch = findViewById(R.id.btnsearch);
btnSimpan = findViewById(R.id.simpan);
radioGroup = findViewById(R.id.rgJK);
cb1 = findViewById(R.id.checkBox1);
cb2 = findViewById(R.id.checkBox2);
cb3 = findViewById(R.id.checkBox3);
cb4 = findViewById(R.id.checkBox4);
cb5 = findViewById(R.id.checkBox5);
cb6 = findViewById(R.id.checkBox6);

btnSimpan.setOnClickListener((V) -> {
selectedRadioButton =
findViewById(radioGroup.getCheckedRadioButtonId());
String jk = selectedRadioButton.getText().toString();
String hb = "";
if (cb1.isChecked()) {
hb += "1." + cb1.getText().toString() + "\n";
}
if (cb2.isChecked()) {
hb += "2." + cb2.getText().toString() + "\n";
}
if (cb3.isChecked()) {
hb += "3." + cb3.getText().toString() + "\n";
}
if (cb4.isChecked()) {
hb += "4." + cb4.getText().toString() + "\n";
}
if (cb5.isChecked()) {
hb += "5." + cb5.getText().toString() + "\n";
}
if (cb6.isChecked()) {
hb += "6." + cb6.getText().toString() + "\n";
}

if(tNim.getText().toString().equals("") ||
tNama.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(), "Masih Kosong !",
Toast.LENGTH_SHORT).show();
}else{
db.execSQL("INSERT INTO tbl_biodata VALUES('"+tNim.getText()
+"','"+tNama.getText()+"','"+tAlamat.getText()+"','"+tTlp.getText()
+"','"+jk+"','"+tTmptlah.getText()+"','"+tTgllahir.getText()+"','"+hb+"');");
Toast.makeText(getApplicationContext(), "Data " + tNim.getText()
+ " Berhasil Tersimpan !", Toast.LENGTH_SHORT).show();
clearText();
}

});

btnsearch.setOnClickListener((view) -> {
Cursor c=db.rawQuery("SELECT * FROM tbl_biodata WHERE
nim='"+tNim.getText()+"'", null);
if(c.moveToFirst()) {
tNim.setText(c.getString(0));
tNama.setText(c.getString(1));
tAlamat.setText(c.getString(2));
tTlp.setText(c.getString(3));
selectedRadioButton.setText(c.getString(4));
tTmptlah.setText(c.getString(5));
tTgllahir.setText(c.getString(6));
String hb = c.getString(7);
btnedit.setEnabled(true);
btnhapus.setEnabled(true);

} else {
Toast.makeText(getApplicationContext(), "NIM " + tNim.getText() +
" Tidak Ditemukan, silakan Input Data baru !",
Toast.LENGTH_SHORT).show();
clearText();
btnSimpan.setEnabled(true);

});
btnedit.setOnClickListener((V)-> {
String hb = "";
if (cb1.isChecked()) {
hb += "1." + cb1.getText().toString() + "\n";
}
if (cb2.isChecked()) {
hb += "2." + cb2.getText().toString() + "\n";
}
if (cb3.isChecked()) {
hb += "3." + cb3.getText().toString() + "\n";
}
if (cb4.isChecked()) {
hb += "4." + cb4.getText().toString() + "\n";
}
if (cb5.isChecked()) {
hb += "5." + cb5.getText().toString() + "\n";
}
if (cb6.isChecked()) {
hb += "6." + cb6.getText().toString() + "\n";
}

String jk = selectedRadioButton.getText().toString();

if (tNim.getText().toString().equals("") ||
tNama.getText().toString().equals("") || tAlamat.getText().toString().equals("")
|| tTlp.getText().toString().equals("") ||
tTmptlah.getText().toString().equals("") ||
tTgllahir.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(), "Masih Kosong !",
Toast.LENGTH_SHORT).show();
} else {
db.execSQL("UPDATE tbl_biodata set nama = '" + tNama.getText() +
"', alamat = '" + tAlamat.getText() + "',tlp = '" + tTlp.getText() + "',jk = '" +
jk + "',tmptlah = '" + tTmptlah.getText() + "', tgllahir = '" +
tTgllahir.getText() + "',hobby = '" + hb + "' where nim = '" + tNim.getText() +
"' ");
Toast.makeText(getApplicationContext(), "Data Mahasiswa " +
tNama.getText() + " Berhasil Diupdate!", Toast.LENGTH_SHORT).show();
clearText();
}
});
btnhapus.setOnClickListener((V)-> {

if (tNim.getText().toString().equals("") ||
tNama.getText().toString().equals("") || tAlamat.getText().toString().equals(""))
{
Toast.makeText(getApplicationContext(), "Masih Kosong !",
Toast.LENGTH_SHORT).show();
} else {
db.execSQL("DELETE FROM tbl_biodata where nim = '" +
tNim.getText() + "' ");
Toast.makeText(getApplicationContext(), "Data Mahasiswa dengan
nim " + tNim.getText() + " Berhasil Dihapus dari database!",
Toast.LENGTH_SHORT).show();
clearText();
selectedRadioButton.setChecked(false);

}
});

}
void clearText() {
tNama.setText("");
tAlamat.setText("");
tTlp.setText("");
tTmptlah.setText("");
tTgllahir.setText("");
cb1.setChecked(false);
cb2.setChecked(false);
cb3.setChecked(false);
cb4.setChecked(false);
cb5.setChecked(false);
cb6.setChecked(false);
radioGroup.clearCheck();
}
}

 Listing ListActivity.java

package com.example.nuralini_182002_a;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListActivity extends AppCompatActivity {

ListView simpleList;
SQLiteDatabase db;
int i;
String[] daftarmahasiswa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);

db=openOrCreateDatabase("NURALINI_182002_A", Context.MODE_PRIVATE, null);


db.execSQL("CREATE TABLE IF NOT EXISTS tbl_biodata(nim VARCHAR PRIMARY
KEY,nama VARCHAR,alamat VARCHAR,jk VARCHAR,tlp VARCHAR,tmptlah VARCHAR,tgllahir
VARCHAR,hobby VARCHAR);");

Cursor c=db.rawQuery("SELECT * FROM tbl_biodata", null);


daftarmahasiswa = new String[c.getCount()];
i=0;
if (c != null ) {
if (c.moveToFirst()) {
do {
daftarmahasiswa[i] = "* "+ c.getString(0)+ " | " +
c.getString(1)+ " | " + c.getString(3)+ " | " + c.getString(4);;
i++;
}while (c.moveToNext());
}
}
simpleList = findViewById(R.id.simpleListView);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
R.layout.listview, R.id.textView, daftarmahasiswa);
simpleList.setAdapter(arrayAdapter);
}
}

 Listing activity_list.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/simpleListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/material_blue_grey_800"
android:dividerHeight="1dp" />
</LinearLayout>

Das könnte Ihnen auch gefallen