postForm()中的infiniteProgress组件问题-codenameone

postForm()中的infiniteProgress组件问题-codenameone,codenameone,Codenameone,我已将所有连接保存在postForm()中。我这样做是因为如果我保留beforeForm(),可能会单击按钮两次或更多次,但问题是在表单的所有组件到达之前,infiniteProgress组件就被处理掉了。它会导致一瞬间出现空白的白色屏幕。如果网络速度慢,则需要更多的时间。我怎样才能使它更方便呢 public class GroupConnection { ArrayList<Map<String,Object>> response; void groupConnect

我已将所有连接保存在postForm()中。我这样做是因为如果我保留beforeForm(),可能会单击按钮两次或更多次,但问题是在表单的所有组件到达之前,infiniteProgress组件就被处理掉了。它会导致一瞬间出现空白的白色屏幕。如果网络速度慢,则需要更多的时间。我怎样才能使它更方便呢

public class GroupConnection {
ArrayList<Map<String,Object>> response;

void groupConnection() {
    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));
            response = (ArrayList<Map<String, Object>>) parsedData.get("root");
        }

        @Override
        protected void postResponse() {
            super.postResponse(); 
        }
    };
    AllUrl allUrl = new AllUrl();
    connectionRequest.setUrl(allUrl.groupsUrl);
    connectionRequest.setPost(false);
    connectionRequest.setTimeout(8000);
    InfiniteProgress ip = new InfiniteProgress();
    Dialog d = ip.showInifiniteBlocking();
    connectionRequest.setDisposeOnCompletion(d);
    NetworkManager.getInstance().addToQueue(connectionRequest);
 }
}
公共类组连接{
阵列响应;
void groupConnection(){
ConnectionRequest ConnectionRequest=新建ConnectionRequest(){
@凌驾
受保护的void readResponse(InputStream输入)引发IOException{
JSONParser JSONParser=新的JSONParser();
Map parsedData=jSONParser.parseJSON(新的InputStreamReader(input));
response=(ArrayList)parsedData.get(“根”);
}
@凌驾
受保护的void postResponse(){
super.postResponse();
}
};
AllUrl AllUrl=新的AllUrl();
connectionRequest.setUrl(allUrl.groupsUrl);
connectionRequest.setPost(false);
connectionRequest.setTimeout(8000);
InfiniteProgress ip=新的InfiniteProgress();
对话框d=ip.showinFiniteBlock();
connectionRequest.setDisposeOnCompletion(d);
NetworkManager.getInstance().addToQueue(connectionRequest);
}
}
作废邮递表格(表格f)方法:

GroupConnection gc=newgroupconnection();
gc.groupConnection();
if(gc.response!=null){
wrapContainer=新容器();
for(映射元素:gc.response){
String tableName=(String)元素.get(“name”);
String initializationdate=(String)元素.get(“initializationdate”);
String areaCode=(String)元素.get(“areaCode”);
String clubAbbr=(String)元素.get(“clubabbrname”);
String charterDate=(String)元素.get(“clubcharterdate”);
Container tableNameDataContainer=新容器(新的FlowLayout(Component.CENTER,Component.CENTER));
TextArea tableName data=新的TextArea(tableName);
tableNameDataContainer.add(tableNameData);
Container InitiationDateDataContainer=新容器(新的FlowLayout(Component.CENTER,Component.CENTER));
TextArea initializationdatedata=新TextArea(initializationdate);
添加(initializationDateData);
Container areaCodeDataContainer=新容器(新流程布局(Component.CENTER,Component.CENTER));
TextArea areaCodeData=新的TextArea(区号);
tableDataMeetingTextArea(areaCodeData、izz、areaCodeDataContainer);
areaCodeDataContainer.add(areaCodeData);
Container clubabrbnamedatacontainer=新容器(新流程布局(Component.CENTER,Component.CENTER));
TextArea clubAbbrNameData=新TextArea(clubAbbr);
添加(clubAbbrNameData);
容器clubCharterDateDataContainer=新容器(新的流程布局(Component.CENTER,Component.CENTER));
TextArea clubCharterDateData=新TextArea(charterDate);
添加(clubCharterDateData);
TableLayout tl1=新的TableLayout(1,5);
containerTableDataGroup=新容器(tl1);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(30),tableNameDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(20),initializationDateDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(15),areaCodeDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(15),clubAbbrNameDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(20),clubCharterDateDataContainer);
添加(containerTableDataGroup);
}
f、 添加(包装容器);
}

您需要将代码修改为事件驱动,当响应到达刷新表单上的数据时,尝试对代码进行以下修改:

public class GroupConnection {
ArrayList<Map<String,Object>> response;

void groupConnection(ActionListener callback) {
    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));
            response = (ArrayList<Map<String, Object>>) parsedData.get("root");
            //the reponse has arrived we need to inform the UI that the data can is ready to be displayed on screen
            Display.getInstance().callSerially(new Runnable(){
             public void run(){
              callback.actionPerformed(null);

             }
            });
        }

        @Override
        protected void postResponse() {
            super.postResponse(); 
        }
    };
    AllUrl allUrl = new AllUrl();
    connectionRequest.setUrl(allUrl.groupsUrl);
    connectionRequest.setPost(false);
    connectionRequest.setTimeout(8000);
    InfiniteProgress ip = new InfiniteProgress();
    Dialog d = ip.showInifiniteBlocking();
    connectionRequest.setDisposeOnCompletion(d);
    NetworkManager.getInstance().addToQueue(connectionRequest);
 }
}
公共类组连接{
阵列响应;
无效groupConnection(ActionListener回调){
ConnectionRequest ConnectionRequest=新建ConnectionRequest(){
@凌驾
受保护的void readResponse(InputStream输入)引发IOException{
JSONParser JSONParser=新的JSONParser();
Map parsedData=jSONParser.parseJSON(新的InputStreamReader(input));
response=(ArrayList)parsedData.get(“根”);
//响应已经到达,我们需要通知用户界面数据可以在屏幕上显示
Display.getInstance().callSerially(new Runnable()){
公开募捐{
callback.actionPerformed(null);
}
});
}
@凌驾
受保护的void postResponse(){
super.postResponse();
}
};
AllUrl AllUrl=新的AllUrl();
connectionRequest.setUrl(allUrl.groupsUrl);
connectionRequest.setPost(false);
connectionRequest.setTimeout(8000);
InfiniteProgress ip=新的InfiniteProgress();
对话框d=ip.showinFiniteBlock();
connectionRequest.setDisposeOnCompletion(d);
NetworkManager.getInstance().addToQueue(connectionRequest);
}
}
作废后附表格(最终表格f)方法:

GroupConnection gc=newgroupconnection();
gc.groupConnection(f,新ActionListener(){
已执行的公共无效操作(操作事件evt){
wrapContainer=新容器();
for(映射元素:gc.response){
String tableName=(String)元素.get(“name”);
String initializationdate=(String)元素.get(“initializationdate”);
String areaCode=(String)元素.get(“areaCode”);
String clubAbbr=(String)元素.get(“clubabbrname”);
public class GroupConnection {
ArrayList<Map<String,Object>> response;

void groupConnection(ActionListener callback) {
    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));
            response = (ArrayList<Map<String, Object>>) parsedData.get("root");
            //the reponse has arrived we need to inform the UI that the data can is ready to be displayed on screen
            Display.getInstance().callSerially(new Runnable(){
             public void run(){
              callback.actionPerformed(null);

             }
            });
        }

        @Override
        protected void postResponse() {
            super.postResponse(); 
        }
    };
    AllUrl allUrl = new AllUrl();
    connectionRequest.setUrl(allUrl.groupsUrl);
    connectionRequest.setPost(false);
    connectionRequest.setTimeout(8000);
    InfiniteProgress ip = new InfiniteProgress();
    Dialog d = ip.showInifiniteBlocking();
    connectionRequest.setDisposeOnCompletion(d);
    NetworkManager.getInstance().addToQueue(connectionRequest);
 }
}
GroupConnection gc = new GroupConnection();
    gc.groupConnection(f, new ActionListener(){
     public void actionPerformed(ActionEvent evt){
        wrapContainer = new Container();
        for (Map<String, Object> element : gc.response) {
            String tableName = (String) element.get("name");
            String inaugurationDate = (String) element.get("inaugurationdate");
            String areaCode = (String) element.get("areacode");
            String clubAbbr = (String) element.get("clubabbrname");
            String charterDate = (String) element.get("clubcharterdate");

            Container tableNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
            TextArea tableNameData = new TextArea(tableName);
            tableNameDataContainer.add(tableNameData);

            Container inaugurationDateDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
            TextArea inaugurationDateData = new TextArea(inaugurationDate);
            inaugurationDateDataContainer.add(inaugurationDateData);

            Container areaCodeDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
            TextArea areaCodeData = new TextArea(areaCode);
            tableDataMeetingTextArea(areaCodeData, izz, areaCodeDataContainer);
            areaCodeDataContainer.add(areaCodeData);

            Container clubAbbrNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
            TextArea clubAbbrNameData = new TextArea(clubAbbr);
            clubAbbrNameDataContainer.add(clubAbbrNameData);

            Container clubCharterDateDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
            TextArea clubCharterDateData = new TextArea(charterDate);
            clubCharterDateDataContainer.add(clubCharterDateData);

            TableLayout tl1 = new TableLayout(1, 5);
            containerTableDataGroup = new Container(tl1);
            containerTableDataGroup.add(tl1.createConstraint().widthPercentage(30), tableNameDataContainer);
            containerTableDataGroup.add(tl1.createConstraint().widthPercentage(20), inaugurationDateDataContainer);
            containerTableDataGroup.add(tl1.createConstraint().widthPercentage(15), areaCodeDataContainer);
            containerTableDataGroup.add(tl1.createConstraint().widthPercentage(15), clubAbbrNameDataContainer);
            containerTableDataGroup.add(tl1.createConstraint().widthPercentage(20), clubCharterDateDataContainer);

            wrapContainer.add(containerTableDataGroup);
        }
        f.add(wrapContainer);
        f.revalidate();
     }
    });