I am newbie in android application development. I am using the Form Stuff example given on http://developer.android.com/resources/tutorials/views/hello-formstuff.html. In this i have used the custom button example.
My code is as below:
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();
}
});
}
}
Its showing following error:
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(){})
I am unable to figure out the reason for such error.
Please help me on this.
Thanks
Pankaj
You're using the wrong OnClickListener. Use this code instead:
button.setOnClickListener(new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Perform action on clicks
Toast.makeText(HelloFormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With