based on the image below, I have NIK & NAMA fields. the concept is when I fill in the NIK field then I press the GET button it will display the name(NAMA FIELD)
Database structure example
NIK | NAMA |
---|---|
96296 | Farrasta |
94878 | Alfian |
Java class
btnGet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NikKry = etNik.getText().toString();
getNama(); // THE FUNCTION
}
});
private void getNama(){
APIRequestData armNama = RetroMaster.konekRetrofit().create(APIRequestData.class);
Call<ResponseMaster> tampilNama = armNama.ardGetNama(NikKry);
tampilNama.enqueue(new Callback<ResponseMaster>() {
@Override
public void onResponse(Call<ResponseMaster> call, Response<ResponseMaster> response) {
// HOW TO CODE PROPERLY ?
}
@Override
public void onFailure(Call<ResponseMaster> call, Throwable t) {
}
});
}
PHP file
<?php
include ("koneksi.php");
$response = array();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$NIK = $_POST["NIK"];
$query = "SELECT NAMA FROM MASTER_KRY WHERE NIK = '$NIK'";
$eksekusi = oci_parse($conn, $query);
$cek = oci_execute($eksekusi);
if($cek > 0){
$response["data"] = array();
while($ambil = oci_fetch_object($eksekusi)){
$F["NAMA"] = $ambil->NAMA;
array_push($response["data"], $F);
}
}else{
$response["pesan"] = "Data tidak tersedia";
}
}
else{
$response["pesan"] = "*&*%4668%*%^$%#*&*(()%$!@#%";
}
echo json_encode($response);
oci_close($conn);
?>
2
Answers
If you used
EditText
then this method will be help you to notify when text change in EditText.If you used
AutoCompleteTextView
then this method will be help you like:This depends on your entity of ResponseMaster. If the entity has field
Nama
and getter setter exists, you can use below: