显示Volley响应的多个文本视图变为空白:Android

时间:2017-07-26 09:22:24

标签: android json textview android-volley

我有一个应用程序,显示了几家公司及其分支机构的列表。 我正在使用排球来获取并显示每个公司的营业时间。 当有一个分支时,营业时间显示正常,但对于有多个分支的公司,营业时间除最后一个营业时间外都是空白。 我在记录时得到的所有细节都是正确的,但不是布局。

以下是我的截击请求代码

    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很新,无法找到解决方法。拜托,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

@Deepak您正在使用不同的数据更新相同的视图,因此JSONArray中的最后一个数据会显示出来。您需要在listView或RecyclerView中显示它。