【问题标题】:Touch Event in blackberry黑莓中的触摸事件
【发布时间】:2012-04-16 11:05:55
【问题描述】:

我创建了一个 VerticalFieldmanager optFieldManager 我在其中添加了一些自定义按钮 然后我想使用触摸事件方法调用按钮的功能 我尝试使用 TouchEvent() 方法 为此,我确实获取了 optFieldManager 的索引,该索引将索引值设为 0 确认该字段存在 但随后我再次要求管理器内的字段返回 -1 值,这意味着没有字段添加到管理器......这不是真的 我调试了代码,发现点击的帖子正确返回了

int index1=optionVertFldMgr.getFieldAtLocation(message.getX(1), message.getY(1)); 

但是 index1 的值是 -1 这是错误的

有什么问题

我已经添加了下面代码的sn-p

protected boolean touchEvent(TouchEvent message) {

            switch(message.getEvent())
            {

            case TouchEvent.CLICK:
            {
                int index=getFieldAtLocation(message.getX(1), message.getY(1));
                //int index1=optionVertFldMgr.getFieldAtLocation(message.getX(1), message.getY(1));
                if(index!=-1)
                {
                    Field field=getField(index);
                    if(field.equals(optionVertFldMgr))  
                    {

                        int index1=optionVertFldMgr.getFieldAtLocation(message.getX(1), message.getY(1));
                        System.out.println("HELOOOOOOO"+((VerticalFieldManager) field).getFieldAtLocation(message.getX(1), message.getY(1)));
                        //int index1=optionVertFldMgr.getFieldWithFocusIndex();
                        if(index1>-1)
                        {
                            Field fld=optionVertFldMgr.getField(index1);
                            if(fld.equals(m_agendaBtn))
                            {
                                fld.setFocus();
                                return true;
                            }else if(fld.equals(m_eventFeedBackBtn))
                            {
                                fld.setFocus();
                                UiApplication.getUiApplication().pushScreen(new EventFeedbackScreen());
                                return true;
                            }
                        }
                    }
                }
            }
            }
            return false;
            }

【问题讨论】:

标签: blackberry touch-event


【解决方案1】:

您始终可以在每个按钮上覆盖Field.navigationClick,甚至可以在屏幕上覆盖一次并从那里管理来自每个字段的所有事件:

    public boolean navigationClick(int status, int time){
        Field f = getLeafFieldWithFocus();
        if(f == button1){
            //do something 1
            return true;    
        } else if(field == button2){
            //do something 2
            return true;
        }
        //more fields
        return false;   
    }

这种方法适用于触摸屏和触控板。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多