I am trying to write a custom dialog box that takes a name from the user. I am getting a “OnClickListener cannot be resolved to a type – The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})” error in Eclipse. Anyone know what I am doing wrong?
Here is my Code:
public void getName(){
Dialog dialog = new Dialog(main.this);
dialog.setContentView(R.layout.customdialog);
dialog.setTitle("New Game");
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
final EditText inputBox = new EditText(this);
//set up text
final TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText("Enter Your Name...");
//set up button
final Button button = (Button) dialog.findViewById(R.id.namebutton);
button.setOnClickListener(new OnClickListener() {
public void onClick() {
String str = inputBox.getText().toString();
setName(str);
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
}
I guess you are importing the wrong
OnClickListener. Make sure you have:instead of