我需要为自定义管理器设置点击/点击事件。
管理器包含几个元素,但我需要整个管理器响应事件,因此如果用户点击/单击管理器内的任何元素,也应该调用事件处理程序。我所做的是将一个changeListener附加到一个采用所有宽度和高度的NullField,但永远不会调用fieldChanged方法
public class TestManager extends Manager{
private BitmapField _icon;
private LabelField _lblTitle;
private NullField nullField;
public TestManager(Bitmap pIcon){
super(Manager.FOCUSABLE);
_icon = new BitmapField(pIcon);
_lblTitle = new LabelField("This is the title");
nullField = new NullField(NullField.FOCUSABLE);
add(_icon);
add(_lblTitle);
add(nullField);
nullField.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
doSomething();
}
});
}
public void doSomething(){
System.out.println("do something!!");
}
public void paint(Graphics graphics)
{
graphics.setColor(Color.DELIMITER_COLOR);
graphics.fillRect(0, 20, Display.getWidth(), 50);
super.paint(graphics);
}
protected void paintBackground(Graphics arg0) {
arg0.setColor(Color.LIGHTGRAY);
arg0.fillRect(0, 0, Display.getWidth(), Display.getHeight());
super.paint(arg0);
}
protected void sublayout(int width, int height) {
setPositionChild(_icon, UIFactory.getBestX(10), UIFactory.getBestX(8));
setPositionChild(_lblTitle, UIFactory.getBestX(60), _topMarginTitle!=0?UIFactory.getBestX(_topMarginTitle):UIFactory.getBestX(15));
setPositionChild(nullField, 0, 0);
layoutChild(_icon, width, UIFactory.getBestX(50));
layoutChild(_lblTitle, width, UIFactory.getBestX(50));
layoutChild(nullField, width, height);
setExtent(width, height);
}
protected boolean navigationClick(int status, int time){
invalidate();
doSomething();
return super.navigationClick(status, time);
}
}
我应该如何让整个经理响应点击/点击?
我正在使用 API 5.0
提前致谢!