高手来帮忙看下这个错误是为什么,跟着视频学的
package com.example.handleractivity;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private Button startbutton=null;
private Button endbutton=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startbutton=(Button)findViewById(R.id.StartButton);
startbutton.setOnClickListener(new StartButtonjt());
endbutton=(Button)findViewById(R.id.EndButton);
endbutton.setOnClickListener(new endbuttonjt());
}
class StartButtonjt implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
handler.post(updateThread);}
}
class endbuttonjt implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
handler.removeCallbacks(updateThread);
}
}
Handler handler=new Handler();
Runnable updateThread=new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
System.out.print("updateThread");
handler.postDelayed(updateThread,3000);
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我是看视频敲的代码跟视频一样 但是为什么我的 startbutton.setOnClickListener报错{The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (MainActivity.StartButtonjt)},
class StartButtonjt 也报错{The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (MainActivity.StartButtonjt)},
onclick也报错{The method onClick(View) of type MainActivity.StartButtonjt must override or implement a supertype method}
[解决办法]
import android.content.DialogInterface.OnClickListener;
import android.view.View.OnClickListener;