我正在尝试编写一个自定义对话框,该对话框需要用户的名称。我得到一个“OnClickListener无法解析为类型 - 类型View中的方法setOnClickListener(View.OnClickListener)不适用于Eclipse中的参数(新的OnClickListener(){})”错误。任何人都知道我在做什么错了?OnClick监听器对于自定义对话框的问题
这里是我的代码:
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();
}