解析JSON并显示在RecyclerView中

 收藏

反馈应用

    String url = "http://www.dohagarage.com/api/v1/sample";

    JsonObjectRequest request = new 
   JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONArray jsonArray = response.getJSONArray("data");

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

        String naame = hit.getString("question");

        mExampleList.add(new ExampleItem(naame));
                        } mExampleAdapter = new ExampleAdapter(MainActivity.this, mExampleList);mRecyclerView.setAdapter(mExampleAdapter);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    });
    mRequestQueue.add(request);
}

This is the code I used to show the questions using json in a RecyclerView. I want show the options in a radio button.

回复
  • 别掏心 回复

    请提供更多代码以更好地理解,但我认为您没有将布局管理器设置为RecyclerView