package com.example.firstproject;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.view.View;
public class MainActivity extends Activity {
int counter;
TextView display;
Button add,sub;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
add=(Button)findViewById(R.id.bAdd);
sub=(Button)findViewById(R.id.bSub);
display =(TextView)findViewById(R.id.tvDisplay);
add.setOnClickListener(new OnClickListener......);
}
}
问题是:OnClickListener无法解析为变量
我已经检查了其他帖子并修复了导入,但仍然没有得到原因
答案 0 :(得分:2)
试试这样:
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Your code here.
}
});
答案 1 :(得分:0)
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//IMPLEMENTATION
}
});