Values of Activity fields are deleted after event in Dialogfragment

Asked

Viewed 43 times

1

I have an Activity that has some text fields. Two of them open a Fragmentdialog when clicked. Dialogs display a list of values that are taken to the Activity via Intent when selected. When this happens the fields that have already been filled in Activity are deleted.

I think it is some problem with the life cycle of Activity, but after hours researching I could not solve this problem.

Any suggestions?

  • Hello, Pedro. Welcome. We need to see the code to get an idea of what’s going on.

1 answer

0

Instead of you wearing one Fragmentdialog use a Dialog. He’s probably resetting his screen because he’s calling a new one Activity.

Using the Dialog you can call a layout creating in xml and give a findViewById in every view of it. You can also send variables and objects from your Activity to the Dialog leaving them static or final. To close the Dialog you have to give a Dismiss() and he returns to his Activity without creating a new one. Ai ta um exemple de como criar um Dialog with a one button layout.

            final Dialog dialog = new Dialog(v.getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.layout_que_vc_criou);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

            Button btnSair = (Button) dialog.findViewById(R.id.btnSair);

            btnSair.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            dialog.show();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.