I use this code in my android project:
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
But, Eclipse says that setButton()
is deprecated. Please, help me with an alternative solution. Thanks!
Use this and set positive or negative button
setButton(int whichButton, CharSequence text, DialogInterface.OnClickListener listener);
refer this http://developer.android.com/reference/android/app/AlertDialog.html#setButton(int, java.lang.CharSequence, android.content.DialogInterface.OnClickListener)
Here's my short and sweet one, an optimization of Android Developer. It's more concise and uses less memory.
setButton() isn't what is deprecated, but that function + argument combination. There is still setButton(), but you need to give an ID for the button as the first argument for setButton():
This is useful if you want to give all your buttons the same OnClickListener:
you can set three kind of buttons with alertDialog
Listener may be outside class or anonymous class like
Good post by Tony Stark here and you can beautify your dialog by adding an icon .. Make sure you have the picture in your drawable folder.
Example