Search code examples
androidgridviewpicasso

Android: Display images in full screen mode using Picasso


Hi i have some images displayed in gridView using Picasso, when i try to open each image (after onItemClickListener) in full screen mode (inside new acivity) it display only the first image in my gridView whatever the image i click, this is my problem. This is my code where i display the images from the url inside gridView and OnItemClickListener.

Picasso.with(ToolDescription.this)
       .load(SaveSettings.ServerURL +"Images/"+ imagepath)
       .into(imageView);

       ls.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(ToolDescription.this, ImageFull.class);
                intent.putExtra("imagepath", SaveSettings.ServerURL +"Images/"+ imagepath);
                startActivity(intent);
            }
        });

            return myView;

This is my second activity (named ImageFull) where i want to display the clicked image:

ImageView imageView = (ImageView) findViewById(R.id.fullImage);
String imagepath = getIntent().getStringExtra("imagepath");

    Picasso.with(ImageFull.this)
                .load(imagepath)
                .noFade()
                .resize(800, 800)
                .centerCrop()
                .into(imageView);

Solution

  • Either set an individual click listener to each imageview or use the int position to pull the correct imagepath from your gridview item array.

    Grid View Android Doc

    This link has a easy to follow code for exactly what you're trying to do.. Use the position to find which element you are clicking on an get the respective image url