我使用firebase发布了一些日期,我需要使用进度对话框来指示用户正在上传数据。我导入进度对话框,我需要在上传之前显示它,并在上传后解除。但是,进度对话框根本不会出现。
任何人都可以告诉我哪里弄错了,谢谢。
private ProgressDialog progressDialog;
progressDialog = new ProgressDialog(this);
public void postHelp() {
progressDialog.setMessage("Posting your request...");
progressDialog.show();
final String postTitle = title.getText().toString().trim();
final String postDesc = desc.getText().toString().trim();
final String postAddress = address.getText().toString().trim();
final String postPhone = phone.getText().toString().trim();
//check input fields
if (!TextUtils.isEmpty(postTitle) && !TextUtils.isEmpty(postDesc)
&& !TextUtils.isEmpty(postAddress) && !TextUtils.isEmpty(postPhone)) {
final DatabaseReference newRequest = database.push();
mDatabaseUser.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
newRequest.child("Title").setValue(postTitle);
newRequest.child("Desc").setValue(postDesc);
newRequest.child("Address").setValue(postAddress);
newRequest.child("Phone").setValue(postPhone);
progressDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Intent main = (new Intent(AddPostActivity.this,MainActivity.class));
main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(main);
}
}
答案 0 :(得分:0)
调用对话框构建器:
AlertDialog.Builder diaog = new AlertDialog.Builder(this,android.R.style.Theme_DeviceDefault_Dialog)
.setTitle(title)
.setMessage(message)
.setPositiveButton(okBtn, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setCancelable(false)
;
然后
dialog.show();
dialog.dismiss();