这是我的大问题:
http://www.bilder-space.de/show_img.php?img=7371f3-1333218887.jpg&size=original
和代码:
package org.madmax.sudoku;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class SudokuActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Set up Click Listener for all Buttons
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
public void onClick(View v) {
switch(v.getId()) {
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
}
}
}
}
错误是:
-void is an invalid type for the variable onCLick()
为什么 Eclipse 会给我这个错误?
最佳答案
您可以像这样在 onCreate 方法中使用 onclick
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// your code here
}
});
}
关于java - 接口(interface) OnClickListener 无法使用我的 onClick 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9958604/