Skip to content

Instantly share code, notes, and snippets.

@dlfinis
Created December 19, 2014 22:05
Show Gist options
  • Save dlfinis/b1e096b71601d4f87582 to your computer and use it in GitHub Desktop.
Save dlfinis/b1e096b71601d4f87582 to your computer and use it in GitHub Desktop.
Button Listener with auto-close Alert Dialog
private View.OnClickListener btnJagger_onClickListener = new View.OnClickListener() {
String message="";
@Override
public void onClick(final View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
message=(getString(R.string.thanks)+"\n"+getString(R.string.about)) ;
builder.setTitle(R.string.company_name);
builder.setMessage(message);
builder.setCancelable(true);
final AlertDialog dlg = builder.create();
dlg.show();
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
dlg.dismiss(); // when the task active then close the dialog
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
}
}, 3000); // after 3 second (or 3000 miliseconds), the task will be active.
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment