I'm creating a AlertDialog using only code and inserting a view for check box. But the check is with a strange gravity behaviour.
How I could put text+box in the middle or at least text on the left with padding for the start.
Thanks.
private void openFilterDialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
builder.setTitle(getString(R.string.filter));
// Set up the input
final CheckBox hideNoResponseBox = new CheckBox(getContext());
//Put the checkBox on the right side
hideNoResponseBox.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
hideNoResponseBox.setText(R.string.hide_no_responses);
hideNoResponseBox.setChecked(hideNoResponse);
hideNoResponseBox.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
hideNoResponseBox.setGravity(View.TEXT_ALIGNMENT_CENTER);
builder.setView(hideNoResponseBox);
// Set up the buttons
builder.setPositiveButton(getString(R.string.do_filter), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (Utils.isDoubleClick()) return;
hideNoResponse = hideNoResponseBox.isChecked();
showLoadingDialog(true);
hideListItem(adapter.getDistanceArrayList());
dialog.dismiss();
}
});
builder.setNegativeButton(getString(R.string.str_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}