I’ve seen this asked a thousand times in a thousand different ways, but still can’t get it to work…
I created a class which I’ve derived from ImageButton. I want to define my “on-click” behavior in the class.
I know I can do something inside my Activity’s onCreate like:
myButton b;
b = (myButton)findViewById(R.drawable.mybutton);
b.setOnClickListener(new View.OnClickListener() {
...etc...
but I want to define the code where it should be, in the derived class.
I first thought I could define it as:
@Override public void onClick(View v) {
…but I get an error saying that I can’t use “@Override” here because “onClick” isn’t in the superclass. (When trying to remove “@Override”, it just builds and runs, but never gets called). I’ve also tried:
@Override public void onClickListener(View v) {
…and several variants of “implements onClickListener” and “implements OnClickListener” to no avail.
This should be fairly simple – any ideas??
Another way: