This is the code that works for me:
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (getArguments() == null) { throw new InvalidParameterException("The key types dialog needs the protocol id to be in the arguments"); } if (mCallback == null) { throw new InvalidParameterException("The key types dialog needs an callback to be set"); } mProtocolId = getArguments().getInt(ApplicationConstants.FragmentsConstants.PROTOCOL_ID); final List<KeyTypeEntity> allKeyTypes = BusinessFacade.getInstance(getActivity()).KeyTypeLogic.getAllKeyTypes(); ArrayAdapter<KeyTypeEntity> keyTypeAdapter = new ArrayAdapter<KeyTypeEntity>(getActivity(), android.R.layout.simple_list_item_1, allKeyTypes); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("").setAdapter(keyTypeAdapter, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final KeyTypeEntity keyTypeEntity = allKeyTypes.get(which); AlertDialog.Builder number = new AlertDialog.Builder(getActivity()); List<String> keyNumbers = new ArrayList<String>(); for (int i = 0; i < 50; i++) { keyNumbers.add("" + (i + 1)); } ArrayAdapter<String> kAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, keyNumbers); number.setTitle("").setAdapter(kAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { addNewKey(keyTypeEntity, which + 1); } }); number.show(); } }).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mCallback.onDialogClosed(); } }); mDialog = builder.create(); return mDialog; }
In the first click handler, I just create a new dialog and show it. This will close the first dialog, open the second, and when the user clicks on an item in the list, the second click handler is called.
Hope this helps, and I'm not too late :)
Cristian chereches
source share