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

  • Home
  • SEARCH
  • 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 8640699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:20:38+00:00 2026-06-12T11:20:38+00:00

I am using the standard gridview source for my app. The problem which i

  • 0

I am using the standard gridview source for my app. The problem which i face is that, when i scroll the images in the gridview, the images change dynamically everytime, having wrong images at the positions. For reference below is the code i use……

  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Set up an array of the Thumbnail Image ID column we want
    String[] projection = {MediaStore.Images.Thumbnails._ID};
    // Create the cursor pointing to the SDCard
    cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
            projection, // Which columns to return
            null,       // Return all rows
            null,
            MediaStore.Images.Thumbnails.IMAGE_ID);
    // Get the column index of the Thumbnails Image ID
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);

    GridView gridView = (GridView) findViewById(R.id.gridview);
    gridView.setAdapter(new ImageAdapter(this));




    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), ImageSelection.class);
            // passing array index
            i.putExtra("imageIndex_from_Activity", position);
            startActivity(i);

        }
    });

> ImageAdapter class

 private class ImageAdapter extends BaseAdapter {

    private Context context;

    public ImageAdapter(Context localContext) {
        context = localContext;
    }

    public int getCount() {
        return cursor.getCount();
    }
    public Object getItem(int position) {
        return position;
    }
    public long getItemId(int position) {
        return position;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView picturesView;
        if (convertView == null) {
            picturesView = new ImageView(context);
            // Move cursor to current position
            cursor.moveToPosition(position);
            // Get the current value for the requested column
            int imageID = cursor.getInt(columnIndex);
            // Set the content of the image based on the provided URI
            picturesView.setImageURI(Uri.withAppendedPath(
                    MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));
            picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            picturesView.setPadding(5, 5, 5, 5);
            picturesView.setLayoutParams(new GridView.LayoutParams(80, 80));
        }
        else {
            picturesView = (ImageView)convertView;
        }
        return picturesView;
    }
}

Attaching screenshots, 1.Before Scrolling 2.Scrolled down and scrolled up again.

before scrolling

when scrolled up again

Why does the order changes??

  • 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-12T11:20:39+00:00Added an answer on June 12, 2026 at 11:20 am

    You’re only setting the image on new views.

    Do the following:

    if (convertView == null) {
        picturesView = new ImageView(context);
        picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        picturesView.setPadding(5, 5, 5, 5);
        picturesView.setLayoutParams(new GridView.LayoutParams(80, 80));    
    } else {
        picturesView = (ImageView)convertView;
    }
    // Move cursor to current position
    cursor.moveToPosition(position);
    // Get the current value for the requested column
    int imageID = cursor.getInt(columnIndex);
    // Set the content of the image based on the provided URI
    picturesView.setImageURI(Uri.withAppendedPath(
    MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using standard BMP images for buttons that come with visual studio. When using
I have an app that is using standard out of the box form validation
I'm building an app in JQM which receives user input using standard form elements.
I am developing a web app using MVC 3 that is using standard form
How to do this using standard methods (without manual iteration through source string)? PS:
I have an application running under WebLogic that is using standard forms authentication. The
My app records calls using standard MediaRecorder. After a few seconds after incoming call
I am using standard windows forms controls under C#. I have two controls which
I have an iPhone application that is mostly using standard controls. There is one
I'm using a standard GridView with a LinqDataSource. The user can sort and page

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.