[英]Why the progress dialog does not show?
My coding works where the data is saved in the real-time database.我的编码在数据保存在实时数据库中的地方工作。 However, the progress dialogue does not work.
但是,进度对话不起作用。 How to put a coding to show if the data failed to be saved in the real-time database?
如果数据没有保存在实时数据库中,如何打码显示?
private void SaveAccountInformation() {
loadingBar.setTitle("Registration Account");
loadingBar.setMessage("Please wait while we are registering you in our system.");
loadingBar.show();
loadingBar.setCanceledOnTouchOutside(true);
String firstname = RegisterFirstName.getText().toString();
String lastname = RegisterLastName.getText().toString();
if (TextUtils.isEmpty(firstname))
Toast.makeText(RegistrationActivity.this, "Enter your first name.", Toast.LENGTH_SHORT).show();
else if (TextUtils.isEmpty(lastname))
Toast.makeText(RegistrationActivity.this, "Last name is required.", Toast.LENGTH_SHORT).show();
else {
String userid = databaseUser.push().getKey();
User user = new User(firstname, lastname);
databaseUser.child(userid).setValue(user);
Toast.makeText(RegistrationActivity.this, "Registration has been successful.", Toast.LENGTH_SHORT).show();
Intent HomeIntent = new Intent(RegistrationActivity.this, home.class);
HomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(HomeIntent);
finish();
}
loadingBar.dismiss();
}
As far as I have understood about your problem you want to track if the data is saved properly or not and show a progress dialog in the meantime.据我了解您的问题,您想跟踪数据是否正确保存并同时显示进度对话框。 I suppose you are using Firebase database and saving the values under a specific node.
我想您正在使用 Firebase 数据库并将值保存在特定节点下。
You might consider having a callback function here I suppose while saving the data in your Firebase real-time database.我想您可能会考虑在此处使用回调函数,同时将数据保存在 Firebase 实时数据库中。
I am rewriting the code.我正在重写代码。 Please note that the code is not tested and modify if you get any syntax errors.
请注意,如果您遇到任何语法错误,代码不会经过测试和修改。
private void SaveAccountInformation() {
ProgressDialog loadingBar = new ProgressDialog(RegistrationActivity.this);
loadingBar.setMessage("Please wait while we are registering you in our system.");
loadingBar.show();
loadingBar.setCanceledOnTouchOutside(true);
String firstname = RegisterFirstName.getText().toString();
String lastname = RegisterLastName.getText().toString();
if (TextUtils.isEmpty(firstname))
Toast.makeText(RegistrationActivity.this, "Enter your first name.", Toast.LENGTH_SHORT).show();
else if (TextUtils.isEmpty(lastname))
Toast.makeText(RegistrationActivity.this, "Last name is required.", Toast.LENGTH_SHORT).show();
else {
String userid = databaseUser.push().getKey();
User user = new User(firstname, lastname);
databaseUser.child(userid).setValue(user)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(RegistrationActivity.this, "Data saved successfully!", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(RegistrationActivity.this, "Failed to save the data", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
});
Intent HomeIntent = new Intent(RegistrationActivity.this, home.class);
HomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(HomeIntent);
finish();
}
}
Hope that helps.希望有帮助。
private ProgressDialog progressDialog = new ProgressDialog(Login.this);
progressDialog.show();
progressDialog.setMessage(getResources().getString(R.string.loading));
progressDialog.setCancelable(false);
progressDialog.dismiss();//close progressDialog
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.