0

I need help for ERROR Help error DialogFragment, exeption on delete item list.

In the code there is the warning for Fragments on DialogFragment. But I can not see where I need to resolve the warning And error in the app when calling the deletething () method

    @Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_edit:
            listener.onEditThing(ThingUri);
            return true;
        case R.id.action_send:
            listener.onSendThing(ThingUri);
            //ADICIONAR IF PARA INSERIR EMAIL E SALVAR
            return true;
        case R.id.action_delete:
            deleteThing();

    }

    return super.onOptionsItemSelected(item);
}

private void deleteThing() {

    confirmDelete.show(getFragmentManager(), "confirm delete");
}


private final DialogFragment confirmDelete = new DialogFragment() {

    @Override
    public Dialog onCreateDialog(Bundle bundle) {

        AlertDialog.Builder builder =
                new AlertDialog.Builder(getActivity());

        builder.setTitle(R.string.confirm_title);
        builder.setMessage(R.string.confirm_message);

        builder.setPositiveButton(R.string.button_delete,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(
                            DialogInterface dialog, int button) {
                        getActivity().getContentResolver().delete(
                                ThingUri, null, null);
                        listener.onThingDeleted();
                    }
                }
        );

        builder.setNegativeButton(R.string.button_cancel, null);
        return builder.create();
    }
};
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 1
    what error and warning ? – John Joe Oct 28 '17 at 15:54
  • warnig in code, and error fail app – Leo Blume Oct 28 '17 at 15:55
  • 1
    what exception you get ? – John Joe Oct 28 '17 at 15:56
  • 1
    Please provide the full error message and call stack that you get from the errors. – Loren Oct 28 '17 at 16:00
  • java.lang.IllegalStateException: Fragment null must be a public static class to be properly recreated from instance state. at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:435) at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:414) at android.support.v4.app.DialogFragment.show(DialogFragment.java:138) – Leo Blume Oct 28 '17 at 16:12
  • `private final DialogFragment confirmDelete = new DialogFragment() {...};` - You can't do that anymore. Create a regular `DialogFragment` subclass instead; e.g., `public static class MyDialogFragment extends DialogFragment {...}`. – Mike M. Oct 28 '17 at 23:26
  • sorry but I did not understand how I'm going to replace it in my code – Leo Blume Nov 02 '17 at 22:01

0 Answers0