Я неофит Ява. Я следовал за учебником на http://developer.android.com/resources/tutorials/views/hello-formstuff.html, чтобы добавить кнопку и обработчик OnClick, скопировав код учебника в мою:
public class FormStuff extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageButton button = (ImageButton) findViewById(R.id.android_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(FormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
}
}
В Eclipse это приводит к двум ошибкам
Description Resource Path Location Type
The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){}) FormStuff.java /FormStuffExample/src/com/example/formstuffexample line 17 Java Problem
The type new DialogInterface.OnClickListener(){} must implement the inherited abstract method DialogInterface.OnClickListener.onClick(DialogInterface, int) FormStuff.java /FormStuffExample/src/com/example/formstuffexample line 17 Java Problem
Что я делаю не так? Спасибо!