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 5934401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:06:32+00:00 2026-05-22T15:06:32+00:00

I have a GridView with 4 images per row, and normally has more than

  • 0

I have a GridView with 4 images per row, and normally has more than the slightly fewer than 5 rows that will fit on the screen at one time.

Originally, it would reset back to the top every time I regenerated its content. So, I took a tip from a post someone made regarding ListAdapter, and came up with the following:

  • Before I regenerate the GridView, I note the value of getFirstVisiblePosition() for the current one.

  • After regenerating it, I call setSelection() with the value I got earlier from getFirstVisiblePosition().

The problem is, every time I regenerate the GridView, it rolls backwards by one row until it reaches the top. It looks like for whatever reason, it returns 0 if EITHER the first OR second row is the first row visible, then returns n-4 (there are 4 items per row) thereafter.

Example:

row 1 is the first visible row: returns 0

row 2 is the first visible row: returns 0

row 3 is the first visible row: returns 4

row 4 is the first visible row: returns 8

As a secondary problem, the first call to setSelection() makes it snap if the user didn’t leave it in exactly the right position. Is there any way to just ask Android, “How many pixels down has the current GridView been scrolled by the user”, and later tell it, “pre-scroll this newly-rendered GridView downward by N pixels” so that the content of the elements might change, but the grid itself will appear stable and remain in the same position it was left in by the user before the update?

Example code:

// (uList = List<User>;)

// see what the current gridview's top position is
// returns 0 for rows zero and one,
// returns n-4 for rows two and beyond (n = row x 4)
int idx = gridview.getFirstVisiblePosition();

gridview.setAdapter(new ImageAdapter(TabViewActivity.this, uList));
// ImageAdapter is subclass of BaseAdapter
// if it matters, it's populating View with slightly-hacked Droid-Fu 
// WebImageView objects (the official version doesn't support overlaying
// bitmaps, and has its own LayoutParams hardcoded).

// restore the previous incarnation's top position
// the "+4" is a nasty hack to make it sort of work for all rows but the first 
gridview.setSelection(idx+4);


public class ImageAdapter extends BaseAdapter {
    // ...
    public View getView(int position, View v, ViewGroup parent) {
        User u = userList.get(position); 
        LayoutParams lp = new LayoutParams(70,70);
        lp.gravity = Gravity.CENTER;
        IBitmapFilter filter = new UserBitmapFilter(u, overlays);
        StyledWebImageView w = new StyledWebImageView(context, u.getIconUrl(app), true, lp, filter);
        w.setTag(u);
        return w;
    }
}

Update: The accepted answer doesn’t quite tell the whole story, but helped me to fix the problem anyway.

In the end, I fixed the problem by reusing the ImageAdapter object instead of generating a new one every time the underlying content changed. It fixed the problem. All the above code was basically replace by:

if (gridviewImageAdapter.update(uList))
    gridviewImageAdapter.notifyDataSetChanged();

and adding a method to the ImageAdapter class:

public boolean update(List<User> uList) {
   // make backup copy of the old list
   // replace the values
   // compare old and new lists, return true if different.
}
  • 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-05-22T15:06:33+00:00Added an answer on May 22, 2026 at 3:06 pm

    You should only need to call notifyDataSetChanged() on the Adapter to reflect changes in the data driving your list.

    How are you regenerating the view?

    It sounds like you’re working against the framework instead of working with it. Watch this video, it helps explain a lot about ListView and updating views from Adapters. I found it really helpful.

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

Sidebar

Related Questions

I have a gridview that has the ability to select rows. <asp:CommandField ShowSelectButton=true SelectImageUrl=~/Images/Icons/Cross.png
I'm working on some code which fills a GridView full of images that have
I have a GridView with three Button columns that are set up with images.
I have a GridView that has it's columns added dynamically in codebehind. I've added
In my android app I have a gridview that I want to show images
I have a Gridview where i have many images that I get from url
I have a GridView that displays images (7 columns of images that are 166dp
I have a GridView in my Android application that has a number of ImageViews
I have an Asp.Net page containing one GridView and a couple of images (google
In my activity i have to show some images. I used gridview in my

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.