So I have searched through a few question here regarding the AlertDialog, and I’m not completely sure what I’m doing, so I am having a hard time relating those questions to my own example. (I’m still new to this whole android programming so please bear with me.)
I have defined this under the public class _ Activity implements OnCLickListener …
public AlertDialog myAlertDialog;
And then I have this under the onClick
public void onClick(View src) {
switch(src.getId()){
case R.id.buttonOk:
if (score==0){
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
myAlertDialog.setTitle("Title");
myAlertDialog.setMessage("Message");
myAlertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
myAlertDialog.show();
}
This line and the line below it have errors:
myAlertDialog.setButton("OK", new DialogInterface.OnClickListener() {
Errors:
1st: Multiple markers at this line
– DialogInterface cannot be resolved to a type
– The method setButton(String, new OnClickListener(){}) is undefined for the type
2nd: DialogInterface cannot be resolved to a type
Can anyone tell me what I am doing wrong please?
Thanks!
I’m pretty sure you just aren’t importing the DialogInterface. Try adding this statement to the beginning of your code.