I use this code in my Eclipse Android project
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
But Eclipse is saying:
This method was deprecated in API level 3. Use setButton(int, CharSequence, android.content.DialogInterface.OnClickListener) with BUTTON_POSITIVE
This was my first step on entering a real programming adventure. It was like, oh I know how to do html website and this must be easy to code -native programming- so lets jump into it without reading any document. This is my first question on this awesome community which is a terrible question. One big suggestion that I can give to any beginner programmer which is; have some idea, dig some document and read open source about how others made before you jump into a new adventure. Patiently read the error that you encounter and try to realise what the real problem is. Thus you don't ask unnecessary question.
This method is deprecated.
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.
There are three kinds of lists available with the AlertDialog APIs: A traditional single-choice list. A persistent single-choice list (radio buttons) A persistent multiple-choice list (checkboxes)
Java
AlertDialog alert = new AlertDialog.Builder(this).create();
alert.setTitle("Error");
alert.setMessage("Sorry, your device doesn't support flash light!");
alert.setButton(Dialog.BUTTON_POSITIVE,"OK",new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alert.show();
Kotlin
var alert: AlertDialog = AlertDialog.Builder(this).create()
alert.setTitle("Error")
alert.setMessage("Sorry, your device doesn't support flash light!")
alert.setButton(Dialog.BUTTON_POSITIVE, "OK", DialogInterface.OnClickListener {
//do your own idea.
dialog, which -> finish() })
alert.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With