gpt4 book ai didi

java - 为什么进度对话框不显示?

转载 作者:搜寻专家 更新时间:2023-11-01 09:24:16 24 4
gpt4 key购买 nike

我的编码在数据保存在实时数据库中的地方工作。但是,进度对话不起作用。数据存入实时数据库失败如何打码显示?

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();
}

最佳答案

据我了解您的问题,您想要跟踪数据是否正确保存并同时显示进度对话框。我想您正在使用 Firebase 数据库并将值保存在特定节点下。

我想您可能会考虑在此处使用回调函数,同时将数据保存在您的 Firebase 实时数据库中。

我正在重写代码。请注意,如果您遇到任何语法错误,代码未经测试和修改。

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();
}
}

希望对您有所帮助。

关于java - 为什么进度对话框不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52000574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com