0

いくつかのCustomButtonを追加したVerticalFieldmanageroptFieldManagerを作成しました。次に、touch eventメソッドを使用してボタンの機能を呼び出したいです。TouchEvent()メソッドを使用してこれを試しました。このために、インデックス値を0として与えるoptFieldManagerのインデックスをフェッチします。これにより、フィールドが存在することが確認されますが、マネージャー内で-1の値を返すフィールドを再度要求します。これは、マネージャーにフィールドが追加されていないことを意味します...これは正しくありません。コードをデバッグしたところ、クリックされた位置が見つかりました。正しく返される

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

しかし、index1の値は-1になりますが、これは間違っています

どうしたの

以下にコードスニペットを追加しました

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;
            }
4

1 に答える 1

1

いつでもField.navigationClickをオーバーライドできます。または、画面で1回オーバーライドして、そこからすべてのフィールドのすべてのイベントを管理することもできます。

    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;   
    }

このアプローチは、タッチスクリーンとトラックパッドの両方で機能します。

于 2012-04-17T07:27:28.267 に答える