如何在图片滚动字段中的图像上实现点击事件?

时间:2011-03-07 11:19:01

标签: blackberry

如何在图片滚动字段中的图片上实现点击事件?

2 个答案:

答案 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());
            }
        }
    });