Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically close dialog on item click #90

Open
danwguy opened this issue Oct 4, 2017 · 1 comment
Open

Programmatically close dialog on item click #90

danwguy opened this issue Oct 4, 2017 · 1 comment

Comments

@danwguy
Copy link

danwguy commented Oct 4, 2017

I am using the sample to create a new blur dialog and everything is working great, when I select an item from the list I start a new activity, and it all works great, but if I hit the back button in the action bar when I get back to the activity that has the blurred dialog the dialog is still open. I have to click somewhere on the screen that is not in the dialog to make it go away. I can't find a way to programmatically close the dialog when a user selects an item in the dialog list.

I am using the following method to create the dialog in a fragment...

@Override
    @NonNull
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_profile_dialog, null);
        TextView text = (TextView) view.findViewById(R.id.follow_or_unfollow);
        if(isSelf) {
            text.setText("Edit Profile");
        } else {
           text.setText((isFollowing) ? "UnFollow" : "Follow");
        }
        RelativeLayout followButton = (RelativeLayout) view.findViewById(R.id.follow_layout);
        RelativeLayout chatButton = (RelativeLayout) view.findViewById(R.id.chat_layout);


        followButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //NEED TO DISMISS DIALOG WINDOW HERE
                if(isSelf) {
                    //activate ProfileEditActivity
                    getActivity().startActivity(new Intent(getActivity(), EditProfileActivity.class));
                } else {
                    Map<String, Object> updates = new HashMap<>();
                    if(isFollowing) {
                        //unfollow
                        updates.put("/following/" + user.getUid() + "/users/" + userID, null);
                        updates.put("/followers/" + userID + "/users/" + user.getUid(), null);
                    } else {
                        updates.put("/following/" + user.getUid() + "/users/" + userID, true);
                        updates.put("/followers/" + userID + "/users/" + user.getUid(), true);
                        //follow
                    }
                    database.getReference().updateChildren(updates);
                    getFragmentManager().beginTransaction().remove(ProfileDialogFragment.this).commit();
                }
            }
        });

        chatButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getContext(), "Implement the start activity for chat", Toast.LENGTH_SHORT).show();
            }
        });
        builder.setView(view);
        return builder.create();
    }

I don't see any example of how to close the dialog when a user selects an item from the dialog window. Please help, I am still pretty new to android and have no idea how to get this dialog to close once the user selects an item in the dialog. Thank you

@tbarthel-fr
Copy link
Member

Hi (=

First of all, thanks for your interest in this quite old project.

If I understood well, you might simply need to call dismiss() just before/after the startActvity

https://developer.android.com/reference/android/app/DialogFragment.html#dismiss()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants