I would like to create a CustomButton
which has a predefined onClick
.
In fact, my object would do the same job than
CustomButton mButton = getViewById(..);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
show_something()
}
Is there a way to embed the Listener
into the CustomButton object that inherits from Button ?
What I would like is to create a CustomButton
in my layout XML file, and not having to mention this button in my activity, which would give:
main.xml:
<LinearLayout xmlns:"...">
<com.mypackage.view.CustomButton
(attributes)/>
</LinearLayout>
CustomButton.java:
class CustomButton extends Button implements... {
@Override
OnClick (or something like that, that's the core of my question, what to put here)
}
myActivity.java
public class myActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Thanks a lot.