Activity field values are deleted after event in DialogFragment

1

I have an Activity that has some text fields. Two of them open a FragmentDialog when clicked. The 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's some problem with the Activity lifecycle, but after hours of searching I could not solve this problem.

Any suggestions?

    
asked by anonymous 04.08.2016 / 02:32

1 answer

0

Instead of using a FragmentDialog use a Dialog . He is probably resetting his screen because he is calling a new Activity .

Using Dialog you can call a layout by creating in xml and give a findViewById in every view of it. You can also send variables and objects from your Activity to Dialog leaving them static or final. To close Dialog you have to give dismiss () and it returns to your activity without creating a new one. Here's an example of how to create a Dialog with a 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();
    
04.08.2016 / 20:10