【问题标题】:Images display in gridview using JSON parsing in android在 android 中使用 JSON 解析在 gridview 中显示图像
【发布时间】:2013-11-15 06:36:37
【问题描述】:

我是 android 应用程序开发的新手。谁能建议我如何在 android 中使用 JSON 解析在 gridview 中显示图像?

【问题讨论】:

    标签: android json gridview


    【解决方案1】:

    您究竟想要做什么,因为 json 解析和在 gridview 中显示图像是两件不同的事情。要么您想从服务器获取图像并使用 json 解析来解析 URL。或者让您的问题清晰易懂。

    【讨论】:

      【解决方案2】:

      在你的项目中添加这个类:JsonParser

      public class ImageDownloader extends AsyncTask<String, Void, Bitmap> {
      
          @Override
          protected Bitmap doInBackground(String... params) {
              // TODO Auto-generated method stub
      
              Bitmap bitmap = null;
              try {
      
                  URL aURL = new URL(params[0]);
                  URLConnection conn = aURL.openConnection();
                  conn.connect();
                  InputStream is = conn.getInputStream();
      
                  // Buffered is always good for a performance plus.
                  BufferedInputStream bis = new BufferedInputStream(is);
                  BitmapFactory.Options options = new BitmapFactory.Options();
                  options.inSampleSize =5;
                  // Decode url-data to a bitmap.
                  bitmap = BitmapFactory.decodeStream(bis, null, options);
      
                  // Close BufferedInputStream
                  bis.close();
      
                  // Close InputStream
                  is.close();
      
                  return bitmap;
              } catch (IOException e1) {
                  e1.printStackTrace();
                  return null;
              }
      
          }
      

      在主要活动中:- 添加网格视图并设置适配器 用你的 URL 调用 asyntask

      ImageDownloader d=new ImageDownloder();
      Bimap b=d.execute("url").get();
      grid = (GridView) findViewById(R.id.grid);// grid view ti view all photos
      AdapterForPics adap = new AdapterForPics(Arraylist, Context);
      grid.setAdapter(adap);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多