2017-07-26 18 views
1

我有一個應用程序,顯示了幾家公司及其分支機構的列表。 我使用凌空取得並顯示每個公司的營業時間。 只有一個分支時,營業時間顯示正常,但對於擁有多個分行的公司,營業時間除最後一個營業時間外均爲空白。 我得到所有正確的日誌記錄,但不是在佈局。顯示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非常陌生,無法想出辦法。請,誰能幫忙?

+0

Log.d(String.valueOf(result),「checcccckkkkkk」);'?你可以請張貼JSON迴應? – FAT

+0

請參閱編輯。 @FAT – devgeek

+0

從哪裏設置數據到TextView?你能發表詳細的代碼嗎? – FAT

回答

0

@Deepak您正在使用不同的數據更新相同的視圖,因此JSONArray的最後數據會顯示出來。您需要在listView或RecyclerView中顯示它。

+0

這應該是一個評論!您有足夠的聲譽發佈評論。 – Piyush

+0

是的Piyush你是對的。 – Aditi

+0

這很重要嗎? – Aditi