How To Create Alert Dialog With Andengine
I am developing game using andengine now i need is to create a alert dialog box i am using this case MENU_OPT: mEngine.runOnUpdateThread(new Runnable() { @Over
Solution 1:
Just make the Object Of Main Activity class and use the Object
activity.runOnUIThread(newRunnable() {
@Overridepublicvoidrun() {
AlertDialog.Builderalert=newAlertDialog.Builder(GameActivity.this);
alert.setTitle("");
alert.setMessage("");
alert.setPositiveButton("OK", newOnClickListener() {
@OverridepublicvoidonClick(DialogInterface arg0, int arg1) {
}
});
alert.show();
}
});
Solution 2:
alert.show();
is not the way of showing alert with andengine.
1.You can use Activity.showDialog()
for alert.
OR
2.You can use AlertDialog.Builder
like:
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
Solution 3:
You have done all the thing right just one change need in your code.
mEngine.runOnUIThread(newRunnable() {
@Overridepublicvoidrun() {
AlertDialog.Builderalert=newAlertDialog.Builder(GameActivity.this);
alert.setTitle("");
alert.setMessage("");
alert.setPositiveButton("OK", newOnClickListener() {
@OverridepublicvoidonClick(DialogInterface arg0, int arg1) {
}
});
alert.show();
}
});
You have to UIThread to display dialog not UpdateThread because both have their independent use.
Post a Comment for "How To Create Alert Dialog With Andengine"