8

I have a DialogFragment which serves as a popup. This DialogFragment has a ListView in it and that uses a BaseAdapter that has custom TableRow. My problem is, it takes about 2 seconds to display the popup fully. Is there any solution, or recommendation that you can give me to display this popup faster.

More details : The TableRow has 2 ImageViews and 3 custom TextViews. The BaseAdapter processes the View because it has to do some stuff like hiding other View, setting texts, etc.

Any help will be appreciated. Thanks! :D

dzep
  • 685
  • 1
  • 8
  • 20

1 Answers1

5

I also had many issues with DialogFragment and in our company we decided to abandon it. The main problem is it needs some time to infiltrate and do Fragment stuff. But before it appears user can interact with screen. E.g. press button multiple times before the popup appears and may lead to unexpected behaviors, you have to consider in your code.

Instead use normal Dialog and set Content View - a custom layout and other parameters

    Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.progress_dialog);
    dialog.setCancelable(false);

    Window window = dialog.getWindow();
    if (window != null) {
        window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    }

    dialog.show();

It helps avoid problems connected with Fragments, Fragment Transactions, State and many others.

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
  • I will try to use Dialog instead of DialogFragment. Fragment transaction takes really long time to display, and so we cannot show the user progress before the actual progress ends. – Serdar Samancıoğlu Feb 24 '20 at 15:51
  • 1
    When you say not to use DialogFragment and instead use normal Dialog, does that mean you simply change the class from extending DialogFragment and make it extend Dialog? – Ben Mora Dec 17 '20 at 12:57