2015-10-09 89 views
0

我在解析中有一个类photo,并且在我的项目中有一个。如何在解析中加载图像

enter image description here

所以我从photo想加载图像并将其与trade_id设置为我imageviews。 告诉我我该怎么做,请!

回答

0

做这样

ParseQuery<ParseObject> queryPhoto = ParseQuery.getQuery("photo"); 
    queryPhoto.whereEqualTo("trade_id",trade_id); 
    queryPhoto.findInBackground(new FindCallback<ParseObject>() { 
     @Override 
     public void done(List<ParseObject> listPhoto, ParseException e) { 
      // TODO Auto-generated method stub 
      if(e == null){ 
       for (ParseObject photo : listPhoto){ 
        ParseFile parseFile = (ParseFile)photo.get("imageFile"); 
        final String imageName =photo.getString("imageName"); 
        if (parseFile != null) { 
          parseFile.getDataInBackground(new GetDataCallback() { 

           @Override 
           public void done(byte[] data, ParseException e) { 
            // TODO Auto-generated method stub 
            if (data != null && e == null) { 
              Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0,data.length); 
              if(imageName.equals("image1")) 
                imageVIew1.setImageBitmap(bitmap); 
               else if(imageName.equals("image2")) 
                imageVIew2.setImageBitmap(bitmap); 
               else if(imageName.equals("image3")) 
                imageVIew3.setImageBitmap(bitmap); 
               else if(imageName.equals("image4")) 
                imageVIew4.setImageBitmap(bitmap);          } 
           } 
          }); 
         } 
       } 
      } 
     } 
    }); 
+0

,但我有4 ImageView的,你的代码只加1的ImageView :( –

+0

你可以imageName –

+0

检查,我想将它保存到位 –

0
@kishore jethava is also right but you can also get url from parse then load that url into imageview with the help of any library like Glide or Picassio or even you can download the image manually from the provided url. 

ParseQuery<ParseObject> queryPhoto = ParseQuery.getQuery("photo"); 
     queryPhoto.whereEqualTo("trade_id",trade_id); 
     queryPhoto.findInBackground(new FindCallback<ParseObject>() { 
      @Override 
      public void done(List<ParseObject> listPhoto, ParseException e) { 
       // TODO Auto-generated method stub 
       if(e == null){ 
        for (ParseObject photo : listPhoto){ 
         ParseFile parseFile = photo.getParseFile("imageFile"); 
         if(parseFile!=null) 
         { 
          final String imageULr=parseFile.getUrl(); 
         Glide.with(context).load(imageULr).into(imageView); 
         } 
         } 
        } 
       } 
      } 
     }); 
+0

我应该怎么做,如果我有4图像,我想将它设置为4 imageview? –

+0

它只加载一个图像@@我有4图像相同trade_id @@ –