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

Application stops when loading a dialog with custom view for the second time #65

Open
4 tasks done
fparrav opened this issue Mar 21, 2018 · 2 comments
Open
4 tasks done

Comments

@fparrav
Copy link

fparrav commented Mar 21, 2018

  • I have verified there are no duplicate active or recent bugs, questions, or requests.
  • I have verified that I am using the latest version of MaterialStyledDialogs.
  • I have given my issue a non-generic title.
  • I have read over the README and Wiki (before asking questions on how to do something).
Details
  • MaterialStyledDialogs version: 2.1
  • Device OS version: 7.1.1
  • Device Manufacturer: HDM
  • Device Name: NOKIA2
Reproduction Steps

1.I add a CustomView that contains 2 ImageButton
2. Then inflate the layout in the activity
3.Then I discard the dialogue that was invoked from a floacting action button
4. I'm invoking the dialogue again

Expected Result

Show the dialog box again

Actual Result

Application crashes with the message: java.lang.IllegalStateException: The specified child already has a parent.You must call removeView () on the child's parent first. in the logcat

@fparrav
Copy link
Author

fparrav commented Mar 21, 2018

I could control the error using the Builder and reusing the MaterialStyledDialog object instead of building it every time inside the floating action button.

@slimTouati
Copy link

Hello , i know i'm a year late , but this may help someone :
View register_layout = LayoutInflater.from(MainActivity.this)
.inflate(R.layout.register_layout, null);
Don't put this line before your onClickListener , put it after it . like this :

    txt_create_account.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            View register_layout = LayoutInflater.from(MainActivity.this)
                    .inflate(R.layout.register_layout, null);
            MaterialStyledDialog.Builder mt =  new MaterialStyledDialog.Builder(MainActivity.this);
                    mt.setIcon(R.drawable.ic_account_circle_black_24dp)
                    .setTitle("Inscription")
                    .setDescription("Veuillez remplir tous les champs")
                    .setCustomView(register_layout)
                    .setNegativeText("Annuler")
                    .onNegative(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            dialog.dismiss();

                        }

                    })
                    .setPositiveText("Confirmer")
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            MaterialEditText edt_register_email = (MaterialEditText) register_layout.findViewById(R.id.edt_email);
                            MaterialEditText edt_register_fname = (MaterialEditText) register_layout.findViewById(R.id.edt_fname);
                            MaterialEditText edt_register_lname = (MaterialEditText) register_layout.findViewById(R.id.edt_lname);
                            MaterialEditText edt_register_password = (MaterialEditText) register_layout.findViewById(R.id.edt_password);
                            MaterialEditText edt_register_phone = (MaterialEditText) register_layout.findViewById(R.id.edt_phone);

                            if (TextUtils.isEmpty(edt_register_email.getText().toString())) {
                                Toast.makeText(MainActivity.this, "Champ email doit etre rempli", Toast.LENGTH_SHORT).show();
                                return;
                            }

                            if (TextUtils.isEmpty(edt_register_fname.getText().toString())) {
                                Toast.makeText(MainActivity.this, "Champ prenom doit etre rempli", Toast.LENGTH_SHORT).show();
                                return;
                            }

                            if (TextUtils.isEmpty(edt_register_lname.getText().toString())) {
                                Toast.makeText(MainActivity.this, "Champ nom doit etre rempli", Toast.LENGTH_SHORT).show();
                                return;
                            }

                            if (TextUtils.isEmpty(edt_register_password.getText().toString())) {
                                Toast.makeText(MainActivity.this, "Champ mot de passe doit etre rempli", Toast.LENGTH_SHORT).show();
                                return;
                            }
                            if (TextUtils.isEmpty(edt_register_phone.getText().toString())) {
                                Toast.makeText(MainActivity.this, "Champ phone doit etre rempli", Toast.LENGTH_SHORT).show();
                                return;
                            }

                             /* registerUser(edt_register_email.getText().toString(),
                              edt_register_name.getText().toString(),
                              edt_register_email.getText().toString());*/
                            else {
                                registerUser(edt_register_email.getText().toString(), edt_register_fname.getText().toString(), edt_register_lname.getText().toString(), edt_register_password.getText().toString(),edt_register_phone.getText().toString());
                                // MainActivity.this.removeDialog();
                                Toast.makeText(MainActivity.this, "Votre inscription est faite avec succés", Toast.LENGTH_LONG).show();
                            }
                        }
                    }).show();
        }
    });

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