Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load multiple images in ImageViews (parse.com)

I'm saving 5 images to my class in parse.com. I'm able to download one image based on objectid in a imageView. I need to download all 5 images to my 5 ImageViews. How can I do this. Any help would be appreciated. Thanks

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Footer");
            // Locate the objectId from the class
    query.getInBackground("tNp607WyQD", new GetCallback<ParseObject>() {
                public void done(ParseObject object,ParseException e) {
                    // TODO Auto-generated method stub
                    // Locate the column named "ImageName" and set
                    // the string
                    ParseFile fileObject = (ParseFile) object.get("imageFile");
                    fileObject.getDataInBackground(new GetDataCallback() {
                                public void done(byte[] data,ParseException e) {
                                    if (e == null) {
                                        Log.d("test","We've got data in data.");
                                        // Decode the Byte[] into
                                        // Bitmap
                                        Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,data.length);
                                        // Get the ImageView from main.xml
                                        //ImageView image = (ImageView) findViewById(R.id.ad1);
                                        ImageView ad1=(ImageView) findViewById(R.id.ad1);
                                        // Set the Bitmap into the
                                        // ImageView
                                        ad1.setImageBitmap(bmp);
                                        // Close progress dialog
                                        progressDialog.dismiss();
                                    } else {
                                        Log.d("test",
                                                "There was a problem downloading the data.");
                                    }
                                }
                            });
                }
            });
}}
like image 385
addy123 Avatar asked Oct 02 '22 20:10

addy123


1 Answers

I'm able to resolve this with help of imageloader class:

public class Login extends Activity {
public ImageLoader imgl;
EditText fullname, mobilenumber, occupation;
 Button save;
 ImageView ad1,ad2,ad3,ad4,ad5,ad6;  
 List<ParseObject> ob;

 private ImageView[] imgs = new ImageView[5];
 ProgressDialog progressDialog;
 int i=0;
 HorizontalScrollView horizontalScrollView1;        

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.userdata);
     imgl=new ImageLoader(getApplicationContext());
     fullname = (EditText) findViewById(R.id.fullname) ;
     mobilenumber = (EditText) findViewById(R.id.mobile) ;
    occupation = (EditText) findViewById(R.id.occupation) ;
     save=(Button) findViewById(R.id.btnSave);      
    horizontalScrollView1=(HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
    ad1=(ImageView) findViewById(R.id.ad1);
    ad2=(ImageView) findViewById(R.id.ad2);
    ad3=(ImageView) findViewById(R.id.ad3);
    ad4=(ImageView) findViewById(R.id.ad4);
    ad5=(ImageView) findViewById(R.id.ad5);
    ad6=(ImageView) findViewById(R.id.ad6);
     imgs[0] = ad2; 
     imgs[1] = ad3; 
     imgs[2] = ad4; 
     imgs[3] = ad5; 
     imgs[4] = ad6;

     progressDialog= ProgressDialog.show(Login.this, "","Downloading Image...", true);
                // Locate the class table named "Footer" in Parse.com
     ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
             "Footer");
     query.orderByDescending("updatedAt");
     try {
        ob = query.find();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     for (ParseObject country : ob) {
         ParseFile image = (ParseFile) country.get("imageFile");
         imgl.DisplayImage(image.getUrl(), imgs[i]);
        i=i+1;
         System.out.println("the urls are"+image.getUrl());
     progressDialog.dismiss();
     }
 }
}
like image 53
addy123 Avatar answered Oct 05 '22 12:10

addy123