如何在图片滚动字段中的图片上实现点击事件?
答案 0 :(得分:2)
抱歉,但覆盖touchEvent
无效,但请尝试覆盖trackwheelClick
:
PictureScrollField pictureScrollField = new PictureScrollField(150, 100){
protected boolean trackwheelClick(int status, int time) {
return super.trackwheelClick(status,time);
};
};
答案 1 :(得分:0)
你可以覆盖touchEvent
PictureScrollField pictureScrollField = new PictureScrollField(150, 100) {
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
return true;
}
return super.touchEvent(message);
}
};
然后添加FieldChangeListener:
pictureScrollField.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if (context == 1) {
Dialog.alert("click:" + ((PictureScrollField)field).getCurrentImageIndex());
}
}
});