2016-09-15 30 views
1

1)ConnectionRequest作为参数连接和Toastbar不显示使用的ActionListener问题

ArrayList<Map<String, Object>> responses; 
public void groupConnection(StateMachine sm, ActionListener al) { 
    ConnectionRequest connectionRequest = new ConnectionRequest() { 
     @Override 
     protected void readResponse(InputStream input) throws IOException { 
      JSONParser jSONParser = new JSONParser(); 
      Map<String, Object> parsedData = jSONParser.parseJSON(new InputStreamReader(input)); 
      responses = (ArrayList<Map<String, Object>>) parsedData.get("root"); 
      Display.getInstance().callSerially(new Runnable() { 
       @Override 
       public void run() { 
        al.actionPerformed(null); 
       } 
      }); 
     } 

     @Override 
     protected void handleException(Exception err) { 
      //System.out.println("handleException " + err); 
     } 

     @Override 
     protected void handleIOException(IOException err) { 
      //toastbar doesnt work here but dialogBox works, if showForm("Groups") is used, toastbar is also shown along with dialogbox 
      //ToastBar.showErrorMessage("Please check your network connection", 4000); 
      //sm.showForm("Groups", null); 
      Dialog.show("", "Please check your network connection", "ok", null); 
     } 
    }; 
    AllUrl allUrl = new AllUrl(); 
    connectionRequest.setUrl(allUrl.groupsMenu); 
    InfiniteProgress ip = new InfiniteProgress(); 
    Dialog d = ip.showInifiniteBlocking(); 
    connectionRequest.setDisposeOnCompletion(d); 
    NetworkManager.getInstance().addToQueue(connectionRequest); 
} 

在connectionRequest代码以上,如果没有网络连接,它给IOException异常:可达时,由下面的handleIOException方法,但如果我处理在那里使用dialogBox,它的工作原理。相反,Toastbar不起作用,为什么呢?如果我使用showForm(“Form”,null)以及dialogBox和toastbar,则会重复调用相同的表单,并且在出现多次对话框时也会看到Toastbar。

2)postForm(形式F)的方法

connectionGroup = new GroupConnection(); 
connectionGroup.groupConnection(StateMachine.this, new ActionListener() { 

@Override 
public void actionPerformed(ActionEvent evt) { 
//checking connectionGroup.responses == null doesnt work since the connectionRequest gives IOException if no network.So Toastbar doesnt work here. 
    if (connectionGroup.responses == null) { 
     ToastBar.showErrorMessage("Please check your network connection", 4000); 
    } 
    if (connectionGroup.responses != null) { 
     for (Map<String, Object> element : connectionGroup.responses) { 
      String tableName = (String) element.get("name"); 
      TextArea nameLabel = new TextArea(tableName.toUpperCase()); 
      f.add(singleRowContainerr); 
     } 
    } 
    } 
} 

在上述postForm方法中,我使用的,以检查是否有网络连接或不通过检查:如果(connectionGroup.responses == NULL){做不服...},它不起作用,因为connectionRequest给IoException &不运行connectionRequest内的代码。

如何解决这个问题?我必须在toastBar中显示“检查连接”,并在文本“无连接”中显示标签。 PS我需要将我的所有组件& connectionRequest放在postForm中,因为我需要在调用connectionRequest之前转到表单。

回答

0

ToastBar绑定到特定的FormDialog将阻止任何形式显示自己。

您已将ToastBar设置为一种形式,然后转换为另一种Form