android how to show a dialog for a specific time
I would like to show an alert dialog that shows a counter(timer of time) and after 10 seconds will automatically disappear.
I have:
builder = new AlertDialog.Builder(this);
builder.setTitle(title);
builder.setMessage(msg);
final EditText input = new EditText(this);
builder.setView(input);
runOnUiThread(new Runnable() {
@Ove开发者_如何学Pythonrride
public void run() {
builder.setMessage("ELEOS");
}
});
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismissDialog(id);
}
});
return builder.create();
which simply creates the dialog.
There is a class android.os.CountDownTimer just for this. Create one and in the onFinish() dismiss your dialog.
精彩评论