I'm having a problem when I click on the button and the progress dialog doesn't show out and directly to other activity. What I want to do is, the progress dialog appear before I go to the other activity. I'm trying to get an nice popup dialog box that shows when the btn_create
is clicked but it just isn't showing. Does anyone has solution?
Here's my code at the moment:
DateFormat formatDateTime = DateFormat.getDateTimeInstance();
Calendar mCurrentDate = Calendar.getInstance();
private EditText mEventTitle;
private EditText mEventLoc;
private EditText mEventDesc;
private TextView text_date;
private TextView text_time;
private ImageButton btn_date;
private ImageButton btn_time;
private Button btn_create;
private Button btn_discard;
private int day,month,year,hour,min;
private DatabaseReference mEventDatabase;
private DatabaseReference mUsersDatabase;
private FirebaseUser mCurrentUser;
private ProgressDialog mPDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_new_event);
mEventTitle = (EditText) findViewById(R.id.eventTitle);
mEventLoc=(EditText)findViewById(R.id.eventLocation);
mEventDesc=(EditText)findViewById(R.id.eventDesc);
text_date = (TextView) findViewById(R.id.eventDate);
text_time = (TextView) findViewById(R.id.eventTime);
btn_date = (ImageButton) findViewById(R.id.pickDateBtn);
btn_time = (ImageButton) findViewById(R.id.pickTimeBtn);
btn_create=(Button)findViewById(R.id.createEvent);
btn_discard=(Button)findViewById(R.id.discardEvent);
mPDialog = new ProgressDialog(AddNewEvent.this);
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
mEventDatabase = FirebaseDatabase.getInstance().getReference().child("Event");
mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(mCurrentUser.getUid());
btn_create.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateEvent();
}
});
}
private void updateEvent() {
mPDialog.setTitle("Posting...");
mPDialog.setMessage("Please wait...");
mPDialog.setCanceledOnTouchOutside(false);
String d = text_date.getText().toString();
String t = text_time.getText().toString();
final String dt = d+" "+t;
final String title_val = mEventTitle.getText().toString().trim();
final String loc_val = mEventLoc.getText().toString().trim();
final String desc_val = mEventDesc.getText().toString().trim();
final String current_uid = mCurrentUser.getUid();
if(!TextUtils.isEmpty(title_val) && !TextUtils.isEmpty(loc_val) && !TextUtils.isEmpty(desc_val) && !TextUtils.isEmpty(dt)){
mPDialog.show();
final DatabaseReference newEvent = mEventDatabase.push();
SimpleDateFormat df = new SimpleDateFormat("EEE, d MMM yyyy 'at' hh:mma");
Date date = new Date();
final String currentDate = df.format(date);
mUsersDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
newEvent.child("title").setValue(title_val);
newEvent.child("location").setValue(loc_val);
newEvent.child("desc").setValue(desc_val);
newEvent.child("date&time").setValue(dt);
newEvent.child("uid").setValue(current_uid);
newEvent.child("postDate").setValue(currentDate);
newEvent.child("username").setValue(dataSnapshot.child("name").getValue());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
mPDialog.dismiss();
Intent mainIntent = new Intent(AddNewEvent.this, UpcomingEvent.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
finish();
}
}