我有一个应用程序,显示了几家公司及其分支机构的列表。 我使用凌空取得并显示每个公司的营业时间。 只有一个分支时,营业时间显示正常,但对于拥有多个分行的公司,营业时间除最后一个营业时间外均为空白。 我得到所有正确的日志记录,但不是在布局。显示Volley回复空白的多个文字查看:Android
下面是我的截击请求的代码,
public void getData(final RelativeLayout timeLayoutCollapse, final RelativeLayout timeLayout, final int) {
//URL for fetching the branch time from the server.
String url = context.getString(site_url) + "branch_time.cfc?method=branchtime&branchid=" + dBranchID;
Log.d(url, "this is urlllll");
StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Log.d(String.valueOf(response), "reqqqqqqqqq");
showJSON(response, timeLayoutCollapse, timeLayout);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
timeLayout.setVisibility(View.GONE);
}
});
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
}
我打电话从getData()方法,
final int size = branchesList.size();
if (size >= 2) {
companyName.setText(branchesList.get(i).getBranchName());
businessHours.setText(branchesList.get(i).getBranchName() + " Business Hours:");
Log.d(String.valueOf(bid), "BARCHIDDDD");
Log.d(branchesList.get(i).getBranchName(), "LIST BRANCH NEWWWWWWW");
timeLayoutCollapse.setVisibility(View.GONE);
getData(timeLayoutCollapse, timeLayout);
}
的JSON解析和显示在做,
public void showJSON(final String response, RelativeLayout timeLayoutCollapse, RelativeLayout timeLayout) {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray("DATA");
final int numberOfItemsInBranch = result.length();
Log.d(String.valueOf(result),"checcccckkkkkk");
timeStatus.setText("business hours are ");
currentStatus.setText("unknown");
日志中的数据如
D/0: LOPPPPPPPPPP
D/AAA Branch: LIST BRANCH NAMEEEEEEE
D/BBB: locaaattiiooon
D/0: this is url with BRANCHH
D/http://the url/FOLDER/branch_time.cfc?method=branchtime&branchid=0: this is urlllll
D/1758: BARCHIDDDD
D/CCCCCC: LIST BRANCH NEWWWWWWW
D/1758: this is url with BRANCHH
D/http://the url/FOLDER/branch_time.cfc?method=branchtime&branchid=1758: this is url
服务器响应的日志数据,
[D/[[670,1758,1671,"08:00","08:00","08:00","08:00","08:00","09:00","Closed","17:00","17:00","17checcccckkkkkk
显示在文本视图中的数据作为
companyTime1.setText(SUN_O + '-' + SUN_C);
companyTime2.setText(MON_O + '-' + MON_C);
其中,
MON_O = companyData.getString(3);
MON_C = companyData.getString(10);
SUN_O = companyData.getString(9);
SUN_C = companyData.getString(16);
我得到所有需要的日志中的数据,但显示它们时,textview文本变得空白。 我对android非常陌生,无法想出办法。请,谁能帮忙?
Log.d(String.valueOf(result),“checcccckkkkkk”);'?你可以请张贴JSON回应? – FAT
请参阅编辑。 @FAT – devgeek
从哪里设置数据到TextView?你能发表详细的代码吗? – FAT