2016-01-13 41 views
2

我已经实现了SwipableContainer,而且目前看起来没有多大反应。SwipableContainer在codenameone中似乎没有响应

当我滑动组件时,它有时卡住或轻扫左边。有时它也不允许点击滑动右键。请参阅附件快照供您参考。

enter image description here

有时它冻结容器滑动。另外,当它拖动右侧,然后容器按钮似乎不可点击。一旦我将中心容器稍微向左拖动,然后右侧容器的按钮变得可点击。

简而言之,swipble容器的总体行为不符合标准。

我需要在我的代码中进行任何更改吗?请建议。

Form hi = new Form("Hi World"); 
hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); 
hi.setScrollable(false); 
TableLayout tableLayout = new TableLayout(1,5); 

Container tableHeaderContainer = new Container(tableLayout); 
tableHeaderContainer.setScrollable(false); 

for(int col=0;col<=4;col++){ 

    Button l1 = new Button("Header " + col+1); 

    l1.setVerticalAlignment(Label.TOP); 
    l1.setUIID("TableHeader"); 
    l1.addActionListener(new ActionListener() { 

    public void actionPerformed(ActionEvent evt) { 
     final InteractionDialog dlg = new InteractionDialog("Hello"); 
     dlg.setLayout(new BorderLayout()); 
     dlg.addComponent(BorderLayout.CENTER, new Label("Hello Dialog")); 
     Button close = new Button("Close"); 
     close.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
       dlg.dispose(); 
      } 
     }); 
     dlg.addComponent(BorderLayout.SOUTH, close); 
     Dimension pre = dlg.getContentPane().getPreferredSize(); 
     dlg.showPopupDialog(new Rectangle((evt.getComponent().getX()+(evt.getComponent().getWidth())), (evt.getComponent().getY()+evt.getComponent().getHeight()), 
     evt.getComponent().getWidth(), evt.getComponent().getHeight())); 
    } 
    }); 

    TableLayout.Constraint constraint = ((TableLayout)tableHeaderContainer.getLayout()).createConstraint(); 
    constraint = setTableConstraint(constraint, col); 
    tableHeaderContainer.addComponent(constraint,l1); 
    } 

    hi.addComponent(tableHeaderContainer); 

    Container tableContainerMain = new Container(); 
    tableContainerMain.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); 
    tableContainerMain.setScrollableY(true); 


    for(int row=0;row<=10;row++){ 
    Container tableContainer = new Container(); 
    tableContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS)); 
    tableContainer.setScrollable(false); 

    Button actionButton = new Button(); 
    tableLayout = new TableLayout(1,5); 
    final Container rowContainer = new Container(tableLayout); 

    Button editJobButton = new Button(); 
    Button editJobButton1 = new Button(); 
    Button editJobButton2 = new Button(); 
    Button editJobButton3 = new Button(); 

    rowContainer.setFocusable(false); 
    rowContainer.setLeadComponent(actionButton); 

    actionButton.addActionListener(new ActionListener() { 

    public void actionPerformed(ActionEvent evt) { 
     Dialog.show("actionButton", "actionButton", "OK",""); 
    } 
    }); 

    for(int col=0;col<=6;col++){ 

     if(col==5){ 

      editJobButton = new Button(); 
      editJobButton.setIcon(theme.getImage("edit.png")); 
      editJobButton.setPressedIcon(theme.getImage("edit-lg.png")); 
      editJobButton.setDisabledIcon(theme.getImage("edit-gr.png")); 
      editJobButton.setUIID("transparent_button_action_new"); 
      editJobButton.setVerticalAlignment(Label.TOP); 
      editJobButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent evt) { 

      } 
      }); 

      editJobButton1 = new Button(); 
      editJobButton1.setIcon(theme.getImage("synch1.png")); 
      editJobButton1.setPressedIcon(theme.getImage("synch-lg.png")); 
      editJobButton1.setDisabledIcon(theme.getImage("synch-gr.png")); 
      editJobButton1.setUIID("transparent_button_action_new"); 
      editJobButton1.setVerticalAlignment(Label.TOP); 
      editJobButton1.addActionListener(new ActionListener() { 

       public void actionPerformed(ActionEvent evt) { 

       } 
      }); 

      editJobButton2 = new Button(); 
      editJobButton2.setIcon(theme.getImage("map1.png")); 
      editJobButton2.setPressedIcon(theme.getImage("map-lg.png")); 
      editJobButton2.setUIID("transparent_button_action_new"); 
      editJobButton2.setVerticalAlignment(Label.TOP); 
      editJobButton2.addActionListener(new ActionListener() { 

       public void actionPerformed(ActionEvent evt) { 

       } 
      }); 

      editJobButton3 = new Button(); 
      editJobButton3.setIcon(theme.getImage("checkin.png")); 
      editJobButton3.setPressedIcon(theme.getImage("checkin-lg.png")); 
      editJobButton3.setDisabledIcon(theme.getImage("checkin-gr.png")); 
      editJobButton3.setUIID("transparent_button_action_new"); 
      editJobButton3.setVerticalAlignment(Label.TOP); 
      editJobButton3.addActionListener(new ActionListener() { 

       public void actionPerformed(ActionEvent evt) { 

       } 
      }); 
      } 
     else{ 

      SpanLabel l2 = new SpanLabel(“This is testing text, This is testing text , This is testing text This is testing text " + (col+1)); 
      l2.setTextUIID("login_title"); 
      l2.setUIID("transparent"); 

      TableLayout.Constraint constraint1 = ((TableLayout)rowContainer.getLayout()).createConstraint(); 
      constraint1 = setTableConstraint(constraint1, col); 
      rowContainer.addComponent(constraint1,l2); 
     } 
    } 

    SwipeableContainer swipeableContainer = new SwipeableContainer(null,BoxLayout.encloseX(editJobButton,editJobButton1,editJobButton2,editJobButton3), rowContainer); 

    CheckBox c = new CheckBox(); 
    tableContainer.addComponent(c); 
    tableContainer.addComponent(swipeableContainer); 
    tableContainerMain.addComponent(tableContainer); 



} 
hi.addComponent(tableContainerMain); 
hi.show(); 


public static Constraint setTableConstraint(Constraint constraint,int column){ 

    switch(column){ 
    case 0: 
    constraint.setWidthPercentage(20);//job# 
    break; 
    case 1: 
    constraint.setWidthPercentage(20);//Address 
    break; 
    case 2: 
    constraint.setWidthPercentage(20);//Schedule Date 
    break; 
    case 3: 
    constraint.setWidthPercentage(20);//Type 
    break; 
    case 4: 
    constraint.setWidthPercentage(20);//Status 
    break; 

    default: 
    constraint.setWidthPercentage(20);//else 
    break; 
    } 

return constraint; 

} 
+0

我想知道这是否仅在涉及多点触摸时发生,因为我在'SwipeableContainer'中看到了与多点触摸有关的潜在问题。 –

+0

@ Shai-即使只有一次触摸,它也会发生。 – Sweety

+0

我只能重现当第二根手指触到某处时,是否有特定的过程来重现此问题? –

回答

1

问题是您设置为在具有导致组件时无法聚焦的rowContainer

当您在一个容器上使用setFocusable(false)时,您要求容器不要响应触摸事件,将此设置与可将接收触摸事件的按钮设置为牵头组件相结合将会导致异常行为。

另外rowContainer不包含actionButton这是主要组成部分。

删除rowContainer.setFocusable(false);,离开setLeadComponent,并确保actionButton被添加到容器中。然后检查这是否解决了问题。

+0

@ Diamond-我已经删除了rowContainer.setFocusable(false)并且已经添加了actionButton作为setLeadComponent(actionButton)。还有什么需要检查吗?仍然问题没有解决。是的,它只发生在设备上运行此代码。 – Sweety