3
My dialog has a list, and when this list has many entries, the dialog cuts the buttons in the middle, as in the image :
How do I set a maximum height not to get cut this way?
Dialog code
public void deleteCategoria(int despesa){
mAba = despesa;
final CategoriaDAO dao = new CategoriaDAO(this);
final List<Categoria> list = dao.getLista(despesa);
ArrayAdapter<Categoria> aa = new ArrayAdapter<>(this,android.R.layout.select_dialog_multichoice,list);
final ListView lv = new ListView(this);
lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
lv.setAdapter(aa);
AlertDialog.Builder ab = new AlertDialog.Builder(this).
setTitle("Apagar categorias");
ab.setView(lv);
ab.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
return;
}
});
ab.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int len = lv.getCount();
SparseBooleanArray checked = lv.getCheckedItemPositions();
for (int y = 0; y < len; y++) {
if (checked.get(y)) {
CategoriaDAO catDAO = new CategoriaDAO(getApplicationContext());
Categoria item = list.get(y);
catDAO.deletar(item);
}else if(checked.size() == 0){
Toast.makeText(getApplicationContext(), "Selecione uma categoria", Toast.LENGTH_SHORT).show();
break;
}
}
Intent intente = new Intent(getApplicationContext(), CategoriaListActivity.class);
intente.putExtra("aba", mAba);
intente.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + Intent.FLAG_ACTIVITY_NO_ANIMATION);
getApplicationContext().startActivity(intente);
}
});
ab.show();
}
Do not create the Listview in the JAVA code, but in a layout in XML
– ramaral
Create a normal layout like Activity xml? how do I put it in the dialog? @ramaral
– Allan Chrystian
Create as if it were one Activity and use
ab.setContentView(R.layout.o_seu_layout);
.– ramaral
I have no way to set a Content view, only setView @ramaral
– Allan Chrystian
I didn’t realize I was using the Builder, I’ll post an answer.
– ramaral