【发布时间】:2013-09-07 07:40:33
【问题描述】:
我正在动态创建按钮,我需要动态设置 setOnClickListener() 我目前正在尝试使用以下代码,但它给了我这个语法错误:
private void AddButton(){
Button btn = new Button(this);
btn.setOnClickListener(OnClick(this));
layout.addView(delBtn);
}
public void OnClick(View v) {
Log.d("Button", "Dynamically created button was clicked");
}
"The method OnClick(View) in the type ActivityExample is not applicable for the arguments ()"
我该如何解决这个问题?
编辑:我需要在AddButton() 方法之外使用单击侦听器方法上的按钮
【问题讨论】:
标签: android onclicklistener android-button