Created
January 2, 2018 12:16
-
-
Save alfianyusufabdullah/d7c59383e8d6a85fc21861f2d688ed8c to your computer and use it in GitHub Desktop.
medium - main2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onClick(View view) { | |
switch (view.getId()) { | |
case R.id.btnLihatData: | |
break; | |
case R.id.btnTambahData: | |
textNama = etNama.getText().toString().trim(); | |
textNim = etNim.getText().toString(); | |
textSemester = etSemester.getText().toString().trim(); | |
if (textNama.isEmpty()) { | |
inputNama.setError("Masukkan Nama Mahasiswa"); | |
etNama.requestFocus(); | |
return; | |
} | |
if (textNim.isEmpty()) { | |
inputNim.setError("Masukkan NIM"); | |
etNim.requestFocus(); | |
return; | |
} | |
if (textSemester.isEmpty()) { | |
inputSemester.setError("Masukkan Semester"); | |
etSemester.requestFocus(); | |
return; | |
} | |
EZQLite.getInstance(MainActivity.this) | |
.doInsert(DatabaseConfig.TABEL_NAME) | |
.putValue(DatabaseConfig.COL_NAMA_MAHASISWA, textNama) | |
.putValue(DatabaseConfig.COL_NIM_MAHASISWA, textNim) | |
.putValue(DatabaseConfig.COL_SEMESTER_MAHASISWA, textSemester) | |
.insert(new OnDatabaseCallback() { | |
@Override | |
public void Success() { | |
hideSoftkey(etNama); | |
etNama.setText(""); | |
etSemester.setText(""); | |
etNim.setText(""); | |
inputNama.setErrorEnabled(false); | |
inputNim.setErrorEnabled(false); | |
inputSemester.setErrorEnabled(false); | |
etNama.clearFocus(); | |
etSemester.clearFocus(); | |
etNim.clearFocus(); | |
Snackbar.make(findViewById(R.id.rootView), "Berhasil Menambah Data", Snackbar.LENGTH_SHORT).show(); | |
} | |
@Override | |
public void Failed(String s) { | |
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment