@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
case R.id.action_delete:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Peringatan");
alertDialogBuilder
.setMessage("Apakah Anda yakin ingin mengapus data ini?")
.setCancelable(false)
.setPositiveButton("Hapus",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int idMhs) {
String id = editTextID.getText().toString();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
RegisterAPI api = retrofit.create(RegisterAPI.class);
Call<Value> call = api.hapus(id);
call.enqueue(new Callback<Value>() {
@Override
public void onResponse(Call<Value> call, Response<Value> response) {
String value = response.body().getValue();
String message = response.body().getMessage();
if (value.equals("1")) {
Toast.makeText(UpdateActivity.this, message, Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(UpdateActivity.this, message, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Value> call, Throwable t) {
t.printStackTrace();
Toast.makeText(UpdateActivity.this, "Jaringan Error!", Toast.LENGTH_SHORT).show();
}
});
}
})
.setNegativeButton("Batal",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
break;
}
return super.onOptionsItemSelected(item);
}