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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:32:17+00:00 2026-06-04T12:32:17+00:00

I have a GridView in android which I fill it with data retrieved from

  • 0

I have a GridView in android which I fill it with data retrieved from a xml resource.
For example I have 15 items in the GridView which are placed in order. The overall height exceeds the Screen height so i have to scroll to see the rest of the items.
The problem is when I scroll back up, the order of the invisible rows have changed. It’s a mysterious behavior as sometimes items swap rows with each other.
Here is my getView method:

public class ImageAdapter extends BaseAdapter {
        public ImageAdapter(Context c, NodeList cuu) {
                cu = cuu;
        }
        public int getCount() {
                Log.d("Node Count",cu.getLength()+"");
                return cu.getLength();
        }
        public Object getItem(int position) {
                return position;
        }
        public long getItemId(int position) {
                return position;
        }
        public View getView(int position, View convertView, ViewGroup parent) {
                View myView = convertView;
                if (convertView == null) {
                    Node nd = cu.item(position);
                    Log.d("nodes","Pos: "+(position)+" Name: "+nd.getNodeName()+" Title: "+nd.getAttributes().getNamedItem("title").getTextContent());
                    int catID = Integer.parseInt(nd.getAttributes().getNamedItem("id").getTextContent());
                    LayoutInflater li = getLayoutInflater();
                    myView = li.inflate(R.layout.grid_item, null);
                   ImageView imageView = (ImageView) myView.findViewById(R.id.grid_item_image);
                   myView.setLayoutParams(new GridView.LayoutParams(70, 100));
                   id.download(nd.getAttributes().getNamedItem("icon").getTextContent(),imageView);
                   TextView textView = (TextView) myView.findViewById(R.id.grid_item_text);
                   textView.setText(nd.getAttributes().getNamedItem("title").getTextContent());
                   myView.setTag((Object) catID);
                }else{
                    //Log.d("nodes","Pos: "+(position));
                }
                return myView;
        }
        private NodeList cu = null;
    }

Update: Well, it’s rather odd. After some more debugging I noticed that in the GridView, the Adapter skips the 13th position, meaning it returns 1 instead of 13 and then moves on to 14!!! (I guess the 13 is bad luck!)

  • 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-04T12:32:18+00:00Added an answer on June 4, 2026 at 12:32 pm

    If that is all the code you have in the getView method you’re not implementing it right:

    public View getView(int position, View convertView, ViewGroup parent) {
            View myView = convertView;
            if (myView == null) {           
                Node nd = cu.item(position);
                int catID = Integer.parseInt(nd.getAttributes().getNamedItem("id")
                        .getTextContent());
                LayoutInflater li = getLayoutInflater();
                myView = li.inflate(R.layout.grid_item, null);
                myView.setLayoutParams(new GridView.LayoutParams(70, 100));         
                myView.setTag((Object) catID);
            } 
            Node nd = cu.item(position);
            Log.d("nodes", "Pos: " + (position) + " Name: " + nd.getNodeName()
                    + " Title: "
                    + nd.getAttributes().getNamedItem("title").getTextContent());
            ImageView imageView = (ImageView) myView
                    .findViewById(R.id.grid_item_image);
            id.download(nd.getAttributes().getNamedItem("icon")
                    .getTextContent(), imageView);
            TextView textView = (TextView) myView
                    .findViewById(R.id.grid_item_text);
            textView.setText(nd.getAttributes().getNamedItem("title")
                    .getTextContent());
            return myView;
        }
    

    I don’t know if the code above works, yours is a bit strange. Anyway, I think the behavior you see its normal because all you do in your adapter is populating the first visible elements and then the adapter will be reusing the exact same elements when you scroll up and down because of the recycling. In the getView you should:

    • Check if the convertView is null:
      • If it is null it’s time to inflate a new View for this GridView‘s element. You could also use the holder pattern to cache looking for the composing Views(instead of searching with findViewById everytime)(You use the setTag element for the inflated View but it’s a piece of data from the Node data element ?!? What do you plan to do with it?!?)
      • If it isn’t null you’ll do nothing(or if you implement the holder pattern you would get the tag with the already searched Views)

    And this is what you should do in that if/else statement

    • After the part above you’ll populate the Views with data(so they hold the apropriate data for that position).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView which is databound to an XML Datasource. For one of
I have few images which are retrieved from my web service. I want to
I have an android gridview which i'm using some custom scrolling going on in,
I have a gridview in which i have a lot of items in three
In my xml layout, I have <TableLayout android:id=@+id/gridview android:layout_height=fill_parent android:layout_width=fill_parent > </TableLayout> and in
I have a gridview I created using this tutorial GridView Android , which works
Have a gridview control which will show X amount of rows. I want to
I have a GridView which I am populating by calling a method to return
I have a GridView what I fill through a LINQ expression. Something like this:
I have a gridview that displays items details, I added two template fields one

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.