2017-03-09 13 views
0

を表示しないように、私はJSONを使って近くの場所を取得し、recyclerviewでそれらを表示するアプリをやっています。私の問題は、私は本当に何が間違っているのか分かりません。すべてがうまく見えるからです。解析JSON recyclerviewが

これはJSONを読み込むための私のコードです:

ます。private void loadRecyclerViewData(){

final ProgressDialog progressDialog = new ProgressDialog(this); 
    progressDialog.setMessage("Loading data ..."); 
    progressDialog.show(); 

    StringRequest stringRequest = new StringRequest(Request.Method.GET, URLDATA, 
      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 
        progressDialog.dismiss(); 

        try { 
         JSONObject jsonObject = new JSONObject(response); 
         JSONArray jsonArray = jsonObject.getJSONArray("results"); 

         for (int i = 0; i < jsonArray.length(); i++) { 

          JSONObject o = jsonArray.getJSONObject(i); 

          List_Item item = new List_Item(o.getString("name"), o.getString("reference")); 
          listItems.add(item); 
          System.out.println("My List Item: " + listItems); 

         } 

         adapter = new MyAdapter(listItems, getApplicationContext()); 
         recyclerView.setAdapter(adapter); 

        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 

       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      progressDialog.dismiss(); 

      Toast.makeText(getApplicationContext(), "Error: " + error.getMessage(), Toast.LENGTH_SHORT).show(); 

     } 
    }); 

    RequestQueue requestQueue = Volley.newRequestQueue(this); 
    requestQueue.add(stringRequest); 

} 

と、これは私のJSONの構造である:

JSON structure

これは私のスタックトレースです。 StackTace

+0

ご要望の前に、ご使用のリサイクラーのビューとアダプターを定義してください。adapter.notifyDatasetChanged(); –

+0

おかげ@Assem、それは今働いて、私は、コードの1行... – Zack

+0

はあなたがこれは –

答えて

1

ますレイアウトマネージャを設定する必要があります。

LinearLayoutManager layoutManager 
    = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); 
reycyclerview.setLayoutManager(layoutManager); 
+0

歓迎されていることを必要と推測何私、私は私のRecyclerviewの設定をしたか:recyclerView =(RecyclerView)findViewById(R.id.recycler_view) ; recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(新しいLinearLayoutManager(この)); – Zack

+0

スタックトレースも共有できますか? – mertsimsek

+0

今すぐ更新しました@mertsimsek – Zack