Wednesday, 2 March 2022

Dialog on close: Keep the view changes

This is my dialog:

@SuppressLint("ValidFragment")
public class Popup extends DialogFragment {
    private final int _layout;

    @SuppressLint("ValidFragment")
    public Popup(int layout) {
        _layout = layout;
    }

    @SuppressLint({"ClickableViewAccessibility", "ResourceType"})
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Nullable
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        final View view =  inflater.inflate(_layout, container, false);

        return view;
    }

And this is how I invoke it:

public class MainActivity extends AppCompatActivity implements View.OnClickListener, Popup.ICustomTts, Popup.ITarget, Popup.IDialog, Popup.IControl {
    private final Popup mPopupTurbine = new Popup(R.layout.fragment_turbine);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button turbineBtn = findViewById(R.id.turbine);
        turbineBtn.setOnClickListener(view -> {
            mPopupTurbine.show(getSupportFragmentManager(), "Speak");
        });

When I click outside of that dialog, it will be closed. The problem is, I do some changes in that dialog (e.g. typed a text in TextView) and then I close that dialog. When I want to show it again, all the changes are lost. So how can I just hide the dialog so that the changes are still there when I re-display it?

I think in MainActivity I could add mPopupTurbine.getDialog().hide(); but where do I add this line of code?



from Dialog on close: Keep the view changes

No comments:

Post a Comment