[英]android error: “The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})”
trying to create a basic android program: i have created two buttons and a text view in fragment_main.xml and when i was writing the basic code i have got some error line(red line) on setOnClickListener method saying "The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})" 尝试创建一个基本的android程序:我在fragment_main.xml中创建了两个按钮和一个文本视图,当我编写基本代码时,我在setOnClickListener方法上看到一些错误行(红线),上面写着“方法setOnClickListener(View。 View类型的OnClickListener不适用于参数(new OnClickListener(){})“
code: 码:
public class MainActivity extends ActionBarActivity {
TextView display;
Button add;
Button sub;
int counter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button add=(Button) findViewById(R.id.add);
Button sub=(Button) findViewById(R.id.sub);
TextView display=(TextView) findViewById(R.id.display);
add.setOnClickListener(new view.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Change your code to this : 将代码更改为此:
add.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
}
});
Also check that you have imported the following 还要检查您是否已导入以下内容
import android.view.View.OnClickListener;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.