Firebase向数据库提交详细信息,如何延迟进度栏?

时间:2019-05-12 19:56:27

标签: android

我不确定我的方法是否合适。我为用户提供了一个提交表单,他们在其中填写了几个字段,然后将其提交到Firebase的实时数据库,我使用进度对话框只是为了通知用户发生了什么事。提交成功后,会将用户带回到主页。

我的代码工作得非常好,但是当我测试提交的速度太快时,进度条会在几秒钟内消失,并且将用户带回到主页。我的计划是以某种方式延迟操作,以便用户看到进度条,但是我不确定如何处理进度条,或者是否建议使用吐司代替?

按钮的监听器

// submitting our details
        submitReservation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                // start the progress bar
                alertDialog.show();
                // When the user presses cancel we replace the current fragment back to the users reservation

                // get our text fields
                String fullname = fullNameText.getText().toString().trim();
                String license = licenseText.getText().toString().trim();
                String time_selection = spinner_time.getSelectedItem().toString();
                String duration = spinner_duration.getSelectedItem().toString();
                String slotSelection = spinner_slot_select.getSelectedItem().toString();

                // Call our validation
                int response = validateReservation(fullname, license, time_selection, duration, slotSelection);

                // if all fields are validated, then we can submist to Firebase
                if (response == 0)
                {
                    // we need the currently logged in user's id
                    String currentUser = FirebaseAuth.getInstance().getCurrentUser().getUid();

                    // construct our reservation object
                    Reservation reservation = new Reservation(currentUser, fullname, license, time_selection, duration, slotSelection, "Progress");

                    // call our method
                    submitDetailsFirebase(reservation);

                }}}

提交到Firebase

private void submitDetailsFirebase(Reservation reservation)
    {
        // make a local reference which should only be instantiated when we need it to clean up memory
        DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("Reservations");
        // get a new key
        String id = databaseReference.push().getKey();
        databaseReference.child(id).setValue(reservation).addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid)
            {



                // Replace the current view with the my reservations page
                getFragmentManager().beginTransaction().replace(R.id.fragments_container_main, new ReserveSpace()).commit();

                // dismiss the dialog
                alertDialog.dismiss();


            }
        });
    }

0 个答案:

没有答案