Reputation: 197
I am writing a simple android program for app, in that there is 2 button , i am just trying click the button & display some msg by clicking , here is my code for two buttons .
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonStart = (Button)findViewById(R.id.buttonStart);
buttonStart.setOnClickListener(startListener); // Register the onClick listener with the implementation above
Button buttonStop = (Button)findViewById(R.id.buttonStop);
buttonStop.setOnClickListener(stopListener); // Register the onClick listener with the implementation above
}
//Create an anonymous implementation of OnClickListener
private OnClickListener startListener = new OnClickListener() {
public void onClick(View v) {
Log.d(logtag,"onClick() called - start button");
Toast.makeText(MainActivity.this, "The Start button was clicked.", Toast.LENGTH_LONG).show();
Log.d(logtag,"onClick() ended - start button");
}
};
// Create an anonymous implementation of OnClickListener
private OnClickListener stopListener = new OnClickListener() {
public void onClick(View v) {
Log.d(logtag,"onClick() called - stop button");
Toast.makeText(MainActivity.this, "The Stop button was clicked.", Toast.LENGTH_LONG).show();
Log.d(logtag,"onClick() ended - stop button");
}
};
my error is saying that "OnClickListener cannot be resolved to a type"
can anyone help me in this . .
Upvotes: 0
Views: 68
Reputation: 132982
"OnClickListener cannot be resolved to a type"
Need to import View.OnclickListener in current Activity :
import android.view.View.OnclickListener;
Upvotes: 1