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