2016-07-28 31 views
1

來自搜索命令的操作不起作用,但來自溢出菜單的操作仍然有效。搜索命令不能與Codenameone中的溢出菜單結合使用

這是我的代碼

getToolbar().addSearchCommand(e -> { 
     String text = (String) e.getSource(); 
     if (text == null || text.length() == 0) { 
      this.undoSearch(this); 
     } else { 
      this.fetchComponents(this, text); 
     } 
     getContentPane().animateLayout(150); 
     this.revalidate(); 
     this.repaint(); 
    }, 4); 



getToolbar().addCommandToOverflowMenu("Enviar", null, (ActionListener) (e) -> { 
     Display.getInstance().scheduleBackgroundTask(() -> { 
      boolean success = this.appView.getService().updateTicket(ticket); 
      if (success) { 
       this.appView.showSuccess("Enviado com sucesso!"); 
      } else { 
       this.appView.showError(new Exception("Ocorreu algum erro ao enviar!")); 
      } 
     }); 
    }); 

我只想做samething喜歡它:



enter image description here

+0

什麼不起作用?請注意,當您單擊搜索按鈕時,標題將替換爲應該輸入查詢的文本字段,這是否會發生? –

+0

不,它不會發生,當我添加搜索命令,並在稍後,OverflowMenu –

回答

1

只是嘗試這樣做,我牛逼預期一樣:

Toolbar.setGlobalToolbar(true); 

Form f = new Form("AAAA", BoxLayout.y()); 

f.getToolbar().addSearchCommand(e -> Log.p("Searching: " + e.getSource())); 
f.getToolbar().addMaterialCommandToOverflowMenu("Hi", FontImage.MATERIAL_3D_ROTATION, e -> Log.p("Overflow")); 

f.show();  

enter image description here

enter image description here

+0

它只適用於當我刪除代碼「this.animateLayout(100);」來自我的班級 –

+0

什麼是「這個」?如果它是表單,那麼是的,它可能會與動畫相沖突以安裝搜索欄。 –

+0

是的,「這個」是我的形式,謝謝:D –