我正在打电话然后得到响应,但是“位置”恢复得很晚,有时不显示数据。我可以访问然后单击按钮事件。
我的问题是,单击按钮后数据无法立即显示,有时甚至无法显示。
JSONArray jsonDataArray = jsonObj.getJSONArray("data");
if (jsonDataArray != null && jsonDataArray.length() > 0) {
if(whichApiCalled.equalsIgnoreCase("school"))
{
vectorSchoolData.clear();
SchoolClass objSchoolData = null;
schoolArray = new String[jsonDataArray.length()];
schoolIdArray = new String[jsonDataArray.length()];
for (int i = 0; i < jsonDataArray.length(); i++) {
objSchoolData = new SchoolClass();
JSONObject objectSchoolData = jsonDataArray.getJSONObject(i);
objSchoolData.setId(objectSchoolData.getString(getString(R.string.school_id_tag)));
objSchoolData.setSchoolName(objectSchoolData.getString(getString(R.string.school_name_tag)));
schoolArray[i] = objSchoolData.getSchoolName();
schoolIdArray[i] = objSchoolData.getId();
objSchoolData.setSchoolAddress(objectSchoolData.getString(getString(R.string.school_address_tag)));
vectorSchoolData.add(objSchoolData);
}
}
else if(whichApiCalled.equalsIgnoreCase("position"))
{
Position_TitleClass objPositionTitle = null;
vectorPositionData.clear();
positionTitleArray = new String[jsonDataArray.length()];
positionTitleIdArray = new String[jsonDataArray.length()];
for (int i = 0; i < jsonDataArray.length(); i++) {
objPositionTitle = new Position_TitleClass();
JSONObject objectPositionData = jsonDataArray.getJSONObject(i);
objPositionTitle.setPositionTitleId(objectPositionData.getString(getString(R.string.position_title_id_tag)));
objPositionTitle.setPositionTitleName(objectPositionData.getString(getString(R.string.position_title_name_tag)));
positionTitleArray[i] = objPositionTitle.getPositionTitleName();
positionTitleIdArray[i] = objPositionTitle.getPositionTitleId();
Log.e("Position title is = " , positionTitleArray[i] + " *************");
vectorPositionData.add(objPositionTitle);
}
}else if(whichApiCalled.equalsIgnoreCase("team"))
{
GetTeamsDetailsClass objTeamsDetails = null;
vectorGetTeamsData.clear();
teamArray = new String[jsonDataArray.length()];
teamIdArray = new String[jsonDataArray.length()];
for (int i = 0; i < jsonDataArray.length(); i++) {
objTeamsDetails = new GetTeamsDetailsClass();
JSONObject objectPositionData = jsonDataArray.getJSONObject(i);
objTeamsDetails.setTeam_id(objectPositionData.getString(getString(R.string.team_id_tag)));
objTeamsDetails.setTeam_name(objectPositionData.getString(getString(R.string.team_name_tag)));
teamArray[i] = objTeamsDetails.getTeam_name();
teamIdArray[i] = objTeamsDetails.getTeam_id();
Log.e("team name is = " , teamArray[i] + " *************");
vectorGetTeamsData.add(objTeamsDetails);
}
}
答案 0 :(得分:0)
您可以使用Retrofit来快速获得响应,而不是这种方式。