- 5 years ago
You can use Android Basic AlertDialog for this no need to use any third party AlertBox
private void showLocationDialog(String title, String Message, int drawable) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title);
builder.setIcon(drawable);
builder.setCancelable(true);
builder.setMessage(Message);
String positiveText = getString(android.R.string.ok);
builder.setPositiveButton(positiveText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//opration do here on Click "Ok"
}
});
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//opration do here on Click "Ok"
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
// display dialog
dialog.show();
}
- 5 years ago
private void createAndDisplayDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); LinearLayout layout = new LinearLayout(this); TextView tvMessage = new TextView(this); final EditText etInput = new EditText(this); tvMessage.setText("Enter name:"); tvMessage.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f); etInput.setSingleLine(); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(tvMessage); layout.addView(etInput); layout.setPadding(50, 40, 50, 10); builder.setView(layout); builder.setNegativeButton("Cancel", (dialog, which) -> { Toast.makeText(this, "Cancel clicked", Toast.LENGTH_SHORT).show(); dialog.cancel(); }); builder.setPositiveButton("Done", (dialog, which) -> { String name = etInput.getText().toString(); Toast.makeText(this, "Name entered: " + name, Toast.LENGTH_SHORT).show(); }); builder.create().show(); }
Hot Questions