Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Custom DialogFragment so slow to display

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

like image 338
dzep Avatar asked May 07 '13 11:05

dzep


Video Answer


1 Answers

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.

like image 150
Misha Akopov Avatar answered Sep 20 '22 12:09

Misha Akopov