avast / android-styled-dialogs

Backport of Material dialogs with easy-to-use API based on DialogFragment
Apache License 2.0
2.15k stars 450 forks source link

Set listener while building a dialog #95

Closed liaohuqiu closed 9 years ago

liaohuqiu commented 9 years ago

In some situation, we will define a Listener neither in a Activity or in a Fragment.

For more convenient usage, we should allow set the Listener while build the dialog. For example:

ListDialogFragment
    .createBuilder(c, getSupportFragmentManager())
    .setTitle("Your favorite character:")
    .setItems(new String[]{"Jayne", "Malcolm", "Kaylee",
        "Wash", "Zoe", "River"})
    .setRequestCode(REQUEST_LIST)
     //  set a Listener
    .setListDialogListener(new IListDialogListener() {
        @Override
        public void onListItemSelected(String value, int number, int requestCode) {

        }

        @Override
        public void onCancelled(int requestCode) {

        }
    })
    .show();

}
TomasKypta commented 9 years ago

Hi, we don't want to support setting dialog listeners in builders since it's a very error-prone feature breaking correct handling of device rotation and causing memory leaks. There are currently no plans to add such feature in future releases. The only safe approaches for handling dialog listeners are via target fragment and activity listeners.