我想實現簡單的按鈕點擊事件,但編譯時出錯代碼。Android按鈕OnClick錯誤
下面是完整的代碼:
public class MainActivity extends Activity{
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
addListenerOnButton();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void addListenerOnButton() {
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
}
});
}
}
的編譯器會發出錯誤addListenerOnButton
方法,該方法如下:
請幫助。
卸下進口DialogInterface.OnClickListener並添加進口view.OnClickListener ... – Lal