【发布时间】:2011-10-11 18:42:18
【问题描述】:
我正在尝试编写一个从用户那里获取名称的自定义对话框。我在 Eclipse 中收到“无法将 OnClickListener 解析为类型 - View 类型中的方法 setOnClickListener(View.OnClickListener) 不适用于参数 (new OnClickListener(){})”错误。有谁知道我做错了什么?
这是我的代码:
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();
}
【问题讨论】:
标签: android