如何动态获取JSON数据并在Horizo​​ntals滚动视图中显示?

时间:2016-03-09 05:39:14

标签: android json scrollview

      JsonObjectRequest jor = new  JsonObjectRequest(url, null,
            new Response.Listener<JSONObject>()  {
                @Override
                public void onResponse(JSONObject response) {

                    try {


                        JSONArray ja = response.getJSONArray("results");

                        ArrayList<Details> myModelList = new ArrayList<Details>();

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

                            JSONObject jsonObject = ja.getJSONObject(i);
                            mymodel = new Details();
                            mymodel.id = Integer.parseInt(jsonObject.optString("id").toString());
                            mymodel.url = jsonObject.getString("resLink");
                            mymodel.resType = jsonObject.getString("resType");
                            mymodel.name = jsonObject.getString("resName");

                            myModelList.add(mymodel);


                            setData(myModelList);

                           ;
                        }

如何在水平滚动视图中显示这些数据我现在正在文本视图中显示这些数据。而且,我想根据resTyp分离这些数据.Means restype是视频然后它将出现在视频水平滚动视图中同样适用于思维导图等

            private void setData(ArrayList<Details> myModelList) {


    txtview = (TextView) findViewById(R.id.textView2);
    txtview2 = (TextView) findViewById(R.id.textView3);
    txtview3 = (TextView) findViewById(R.id.textView4);


    txtview.setText(mymodel.getUrl());
    txtview2.setText(mymodel.getResType());
    txtview3.setText(mymodel.geturl());


}

我的JSON低于

        {  
      "results":[  
       {  
     "id":37,
     "resType":"Multiple Choice Questions",
     "resLink":"14",
     "resName":"Multiple choice questions",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":38,
     "resType":"Mind Maps",
     "resLink":"upload/7/crops.jpg",
     "resName":"Crops",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":40,
     "resType":"Mind Maps",
     "resLink":"upload/7/dispersal of seeds.tif",
     "resName":"Dispersal of seeds",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":41,
     "resType":"Mind Maps",
     "resLink":"upload/7/reproduction in plants.jpg",
     "resName":"Reproduction in plants",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":42,
     "resType":"Videos",
     "resLink":"HA2yLweR0f8",
     "resName":"Part 1",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  },
  {  
     "id":43,
     "resType":"Videos",
     "resLink":"vzduIRvu0qk",
     "resName":"Part 2",
     "canDelete":false,
     "canEdit":false,
     "canApprove":false
  }


  ],
   "status":"OK"
}                                 

0 个答案:

没有答案