jublikon
jublikon

Reputation: 3437

onSelect Interface for Material Dialog

I have successfully implemented the Material Dialog:

Material Dialog

Now I want to upate a label in the Fragment Drawer when I get a selection in the Material Dialog. So I thought: easy, just implement the interfaces and you will have the callback methods. But the methods are never ran.

I have tried some of the methods, but none of them work because they are never run.

 public class FragmentDrawer extends Fragment implements MaterialDialog.ListCallbackSingleChoice, MaterialListPreference.OnPreferenceClickListener, MaterialDialog.OnShowListener, MaterialDialog.OnClickListener{
(...)
      @Override
        public boolean onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
            SnackbarManager.show(
                    Snackbar.with(getActivity())
                            .text("Single-line snackbar"));
            return false;
        }
}

The Dialog:

new MaterialDialog.Builder(getActivity())
                                                    .title(R.string.title)
                                                    .items(R.array.items)
                                                    .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
                                                        @Override
                                                        public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                                                            /**
                                                             * If you use alwaysCallSingleChoiceCallback(), which is discussed below,
                                                             * returning false here won't allow the newly selected radio button to actually be selected.
                                                             **/
                                                            return true;
                                                        }
                                                    })
                                                    .positiveText(R.string.positive_text)
                                                    .showListener(new DialogInterface.OnShowListener() {
                                                        @Override
                                                        public void onShow(DialogInterface dialog) {
                                                        }
                                                    })
                                                    .show();

Thanks for help!

Upvotes: 0

Views: 802

Answers (1)

Anton Kovalyov
Anton Kovalyov

Reputation: 932

Did you try this? :

public class FragmentDrawer extends Fragment implements MaterialDialog.ListCallbackSingleChoice, MaterialListPreference.OnPreferenceClickListener, MaterialDialog.OnShowListener, MaterialDialog.OnClickListener{
(...)
      @Override
        public boolean onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
            SnackbarManager.show(
                    Snackbar.with(getActivity())
                            .text("Single-line snackbar"));
            return false;
        }
}


new MaterialDialog.Builder(getActivity())
                                                    .title(R.string.title)
                                                    .items(R.array.items)
                                                    .itemsCallback(this)
                                                    .positiveText(R.string.positive_text)
                                                    .showListener(new DialogInterface.OnShowListener() {
                                                        @Override
                                                        public void onShow(DialogInterface dialog) {
                                                        }
                                                    })
                                                    .show();

Upvotes: 1

Related Questions