我在这里遇到问题,我想处理一些改造来获取一些数据并将其插入到ArrayList中
在此之前,我执行第一次改造以获取第一个数据并将其放入Arraylist中,如果完成此过程,我会调用另一个改进来获取第二个数据并将其添加到Arraylist之前。我这样做了4次以获得完整的数据。 这是json数据:
4请求的示例参数:
{"type":"search","block":"A","date":"2015-02-12","subblock":"1"}
{"type":"search","block":"B","date":"2015-02-12","subblock":"5"}
{"type":"search","block":"C","date":"2015-02-12","subblock":"3"}
{"type":"search","block":"D","date":"2015-02-12","subblock":"7"}
所有4个请求的响应都相同
{
"code":"00",
"value":[
{
"data1":"data1",
"data2":"data2",
...
},
{
"data1":"data1",
"data2":"data2",
...
},
...
]
}
但如果我逐一执行它,则需要更多时间, 所以我想同时执行4次改装并将其放置在Arraylist中,
有没有办法做到这一点?
这个案例的一些代码或参考可能非常有用吗?感谢
申请我的代码:
public void getBlockData(){
String blockType = "";
switch (blockIndicator) {
case 1:
blockType = "A";
break;
case 2:
blockType = "B";
break;
case 3:
blockType = "C";
break;
case 4:
blockType = "D";
break;
}
ApiConnection.getBlockList(getApplicationContext(), new BlockListListener() {
@Override
public void onFlightResponseSuccess(ArrayList<Block> blocks) {
if (getApplicationContext() != null) {
if (blocks != null) {
try {
blockArrayList.addAll(blocks);
Collections.sort(blockArrayList);
BlockAdapter blockAdapter = new BlockAdapter(getApplicationContext(), blockArrayList);
listBlock.setAdapter(blockAdapter);
} catch (NullPointerException e) {
}
}
}
}
}, new OnLoadingProgressBar() {
@Override
public void onLoadingStart(String loadingString) {
progressBarBlock.setVisibility(View.VISIBLE);
textBlockLoading.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingStop() {
progressBarBlock.setVisibility(View.GONE);
textBlockLoading.setVisibility(View.GONE);
listBlock.setVisibility(View.VISIBLE);
blockIndicator = blockIndicator + 1;
if (blockIndicator < 5) {
getBlockList();
}
}
});
}