我在android應用開發的新手。 我使用http://developer.android.com/resources/tutorials/views/hello-formstuff.html給出的形式的東西的例子。在這個我已經使用自定義按鈕的例子。自定義按鈕例如不工作
我的代碼如下:
package com.example.helloformstuff;
import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class HelloFormStuff extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(HelloFormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
}
}
它顯示以下錯誤:
The type new DialogInterface.OnClickListener(){} must implement the inherited
abstract method DialogInterface.OnClickListener.onClick(DialogInterface, int)
- The method setOnClickListener(View.OnClickListener) in the type View is not
applicable for the arguments (new DialogInterface.OnClickListener(){})
我無法弄清楚這種錯誤的原因。
請幫我解決這個問題。
感謝
潘卡
你知道爲什麼這樣寫嗎?爲什麼不能只有一個聽衆? – user219882 2012-03-05 20:30:06