我想创建一个CustomButton具有预定义的onClick.事实上,我的目标是做同样的工作
CustomButton mButton = getViewById(..);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
show_something()
}
有没有办法将其嵌入Listener从Button继承的CustomButton对象?我想要的是CustomButton在我的布局XML文件中创建一个,而不必在我的活动中提到这个按钮,这将给出:
main.xml中:
(attributes)/>
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);
}
}
非常感谢.