Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8268255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:49:04+00:00 2026-06-08T05:49:04+00:00

I’m trying to load all images from sdcard’s phone on a GridView. I implemented

  • 0

I’m trying to load all images from sdcard’s phone on a GridView. I implemented the code bellow but it is loading just a few photos and repeating it a hundred times. Don’t have idea what i’m doing wrong!

This is the onCreate method:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grid_images);

    //GridView
    imagesGridView = (GridView) findViewById(R.id.imagesGridView);

    //Do the query
    externalContentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;        

    String[] projection = {MediaStore.Images.Media._ID}; 
    String selection = "";
    String [] selectionArgs = null;
    externalCursor = getContentResolver().query(externalContentUri,projection,selection,selectionArgs,null); 
    externalColumnIndex = externalCursor.getColumnIndex(MediaStore.Images.Media._ID);

    //Gets the adapter
    myAdapter = new ImageAdapter(this);
    imagesGridView.setAdapter(myAdapter);   
    imagesGridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Toast.makeText(GridImages.this, "" + position, Toast.LENGTH_SHORT).show();
        }
    });

}

This is my custom adapter:

public class ImageAdapter extends BaseAdapter {
    private Context mContext;


    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return externalCursor.getCount();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            externalCursor.moveToPosition(position);
            int imageID = externalCursor.getInt( externalColumnIndex );
            Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,Integer.toString(imageID));

            imageView.setImageBitmap(loadThumbnailImage(uri.toString()));   

        } else {
            imageView = (ImageView) convertView;
        }


        return imageView;
    }

    protected Bitmap loadThumbnailImage( String url ) {
        // Get original image ID
        int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));

        // Get (or create upon demand) the micro thumbnail for the original image.
        return MediaStore.Images.Thumbnails.getThumbnail(mContext.getContentResolver(),
                            originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:49:06+00:00Added an answer on June 8, 2026 at 5:49 am

    Your getView method should be:

       if (convertView == null) {  // if it's not recycled, initialize some attributes
                imageView = new ImageView(mContext);
        } else {
             imageView = (ImageView) convertView;
        }
        externalCursor.moveToPosition(position);
        int imageID = externalCursor.getInt( externalColumnIndex );
        Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,Integer.toString(imageID))
        imageView.setImageBitmap(loadThumbnailImage(uri.toString()));   
        return imageView;
        }
    

    With your current code you’re setting the images only for the first time when GridView requires images(like when it first appears on the screen), for the other rows the old ones get recycled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.