Im using a DialogFragment to show a Dialog with a multi choice items, it shows the Dialog but without the items, there is no checkboxes to select.
This is how i invoke the dialog:
botAddMedicacion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment fragAddMedic = new AnadirMedicacionFragment();
fragAddMedic.show(getFragmentManager(), "addMedicacion");
}
});
And this is the AnadirMedicacionFragment code:
final CharSequence[] items={".NET","J2EE","PHP"};
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
medicSelec = new ArrayList();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.anadir_medicacion);
// elementos de la lista
builder.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked) {
medicSelec.add(which);
} else if (medicSelec.contains(which)) {
medicSelec.remove(Integer.valueOf(which));
}
}
});
// boton ok
builder.setPositiveButton(R.string.anadir, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
// boton cancelar
builder.setNegativeButton(R.string.cancelar, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
The item list is passed in builder.setMultiChoiceItems(items, null[...]
It seems it works, but there are no checkboxes or list.
The problem is that you have a setMessage
and a setMultiChoiceListener
. You can only have one of them. Try this:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.anadir_medicacion);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With