Android Firebase向数据库提交详细信息,如何延迟进度条?
我不确定我的方法是否合适。我有一个提交表单供用户填写几个字段,然后提交到Firebase的实时数据库,我使用一个进度对话框来通知用户发生了什么事情。提交成功后,用户将返回主页面 我的代码运行得非常好,但是当我测试提交速度时,进度条会在几秒钟内消失,用户会返回主页。我的计划是以某种方式延迟操作,以便用户看到进度条,但我不确定如何接近它,或者是否建议使用toast 按钮的侦听器Android Firebase向数据库提交详细信息,如何延迟进度条?,android,Android,我不确定我的方法是否合适。我有一个提交表单供用户填写几个字段,然后提交到Firebase的实时数据库,我使用一个进度对话框来通知用户发生了什么事情。提交成功后,用户将返回主页面 我的代码运行得非常好,但是当我测试提交速度时,进度条会在几秒钟内消失,用户会返回主页。我的计划是以某种方式延迟操作,以便用户看到进度条,但我不确定如何接近它,或者是否建议使用toast 按钮的侦听器 // submitting our details submitReservation.setOnClic
// 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();
}
});
}
private void submitDetailsFirebase(保留)
{
//创建一个本地引用,只有当我们需要它来清理内存时才应该实例化它
DatabaseReference DatabaseReference=FirebaseDatabase.getInstance().getReference().child(“保留”);
//换把新钥匙
String id=databaseReference.push().getKey();
databaseReference.child(id).setValue(reservation).addOnSuccessListener(新的OnSuccessListener()){
@凌驾
成功时公开作废(作废避免)
{
//将当前视图替换为“我的预订”页面
getFragmentManager().beginTransaction().replace(R.id.fragments\u container\u main,new ReserveSpace()).commit();
//关闭对话框
alertDialog.disclose();
}
});
}
如果可能,用户不应该不必要地查看UI更新。所以,对于快速的UI更改更新,敬酒会更好。我会考虑把你的实现放在原来的位置,直到你做了一些真实世界的测试。你经常会发现,你在开发过程中所经历的理想条件在现实世界中并不总是可以重现的,在现实世界中,移动(以及不太完美的)网络是很常见的。非常感谢各位提供的提示,非常感谢。有时你会发现很难做出这些决定,因为你总是希望最终用户拥有尽可能好的体验。如果可能,用户不应该不必要地查看UI更新。所以,对于快速的UI更改更新,敬酒会更好。我会考虑把你的实现放在原来的位置,直到你做了一些真实世界的测试。你经常会发现,你在开发过程中所经历的理想条件在现实世界中并不总是可以重现的,在现实世界中,移动(以及不太完美的)网络是很常见的。非常感谢各位提供的提示,非常感谢。有时你会发现很难做出这些决定,因为你总是希望最终用户拥有尽可能好的体验。