如何在我的自定义对话框上显示进度对话框?

时间:2017-12-15 05:32:49

标签: android android-dialog

我有一个打开的自定义对话框,有一些任务我必须在其上显示我的进度对话框。但我想我的自定义对话框下面会显示进度对话框。这是我试过的代码

我的进度对话框代码

KProgressHUD是第三方图书馆

private void progressDialog() {
    kProgressHUD = new KProgressHUD(getActivity());
    if (!kProgressHUD.isShowing()) {
        kProgressHUD.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                .setLabel("Please wait")
                .setCancellable(false)
                .setAnimationSpeed(2)
                .setDimAmount(0.5f)
                .show();
    }
}

我的自定义对话框代码

final Dialog dialog = new Dialog(consumerHomeActivity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.custom_dialog_select_vendor);
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(false);
    Window window = dialog.getWindow();
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    WindowManager.LayoutParams wlp = window.getAttributes();
    wlp.gravity = Gravity.CENTER;
    window.setAttributes(wlp);

    loadVendorsListFromFirebaseDB(dialog, bookingType);
    dialog.show();

我调用进度对话框方法的方法

private void loadVendorsListFromFirebaseDB(final Dialog dialog, final String bookingType) {

    progressDialog();

    final ArrayList<VendorsList> arrayListVendorsList = new ArrayList<>();
    final ListView vendorsListLv = dialog.findViewById(R.id.custom_dialog_select_vendor_list_lv);

    DatabaseReference databaseReferenceVendorsList = firebaseDatabase.getReference("vendorsList");

    databaseReferenceVendorsList.addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
        @Override
        public void onDataChange(final com.google.firebase.database.DataSnapshot dataSnapshot) {
            arrayListVendorsList.clear();

            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {

                String vendorEmailId = postSnapshot.getKey();
                String vendorName = postSnapshot.child("vendorName").getValue(String.class);

                VendorsList vendorsList = new VendorsList();
                vendorsList.setVendorEmailID(vendorEmailId);
                vendorsList.setVendorName(vendorName);

                arrayListVendorsList.add(vendorsList);

            }

            if (arrayListVendorsList.size() == 0) {
                StaticMethods.customSnackBar(consumerHomeActivity.parentLayout, "Sorry, no vendors available right now",
                        getResources().getColor(R.color.colorPrimaryDark),
                        getResources().getColor(R.color.error_orange), 3000);
            }

            vendorsListAdapter = new VendorsListAdapter(consumerHomeActivity, arrayListVendorsList);
            vendorsListLv.setAdapter(vendorsListAdapter);

            dismissDialog();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

}

3 个答案:

答案 0 :(得分:3)

只需轻扫线

即可
loadVendorsListFromFirebaseDB(dialog, bookingType);
dialog.show();

dialog.show();
loadVendorsListFromFirebaseDB(dialog, bookingType);

这是因为您在显示progressdialog后显示对话框

答案 1 :(得分:0)

在显示Dialog之前显示progess对话框。将其用作

[order_multi_count status="processing"]

建议使用DialogFragment代替Dialog。它是一个具有对话框外观的片段,更适合您的需要。

答案 2 :(得分:0)

在显示自定义对话框后,您首先要加载数据列表。因此,您的进度对话框不会显示在自定义对话框上。

请更改您的代码,如下所示,以显示第一个自定义对话框,并在加载数据列表后。

final Dialog dialog = new Dialog(consumerHomeActivity);

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog_select_vendor);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(false);
Window window = dialog.getWindow();
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.CENTER;
window.setAttributes(wlp);

dialog.show();
loadVendorsListFromFirebaseDB(dialog, bookingType);