The screen is lit, but the dialog is not displayed

I created the list inside the Snippet using the adapter. I want to display a different dialog box for each of the items in the list when clicked. I added a listener to the elements of the list and wrote code to display a dialog box for one of the elements (the second). However, when I click this item, the phone screen dims, but the dialog does not appear . I have added the appropriate code below. I searched a lot about this problem on the Internet and tried many different things myself, but nothing works. Everything else in the application works fine.

Any help would be really appreciated. Thanks in advance!

Dialog Class:

public class GenreDialogFragment extends DialogFragment{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    AlertDialog dialog = builder.create();
    builder.setTitle(R.string.title_genre_dialog);
    builder.setMessage("Are you sure?");
    builder.setPositiveButton("OK",  new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // on success
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    return dialog;
}
}

The class of parent fragments in which I want the dialog box to display:

public class FragmentAddWatchedMovie extends ListFragment{
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SetListAdapter();
    SetClickListener();

}
private void SetClickListener() {
    ListView listView = (ListView) getView().findViewById(android.R.id.list);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position){
                case 0:{
                    FragmentManager manager = getFragmentManager();
                    GenreDialogFragment fragment = new GenreDialogFragment();
                    fragment.setTargetFragment(FragmentAddWatchedMovie.this,0);
                    fragment.show(manager, "GenreDialog_Fragment");
                    break;

                }
                case 1:{

                }
                case 2:{

                }
                case 3:{

                }
                case 4:{

                }
                case 5:{

                }
            }

        }
    });

}
+4
1

: "AlertDialog dialog = builder.create();" Dialog.

, :)

+2

Source: https://habr.com/ru/post/1653704/


All Articles