Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy items change order upon scrolling in Android GridView?
    primarykey
    data
    text
    <p>I have a GridView in android which I fill it with data retrieved from a xml resource.<br> 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.<br> 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 <code>getView</code> method:</p> <pre><code>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; } </code></pre> <p><strong>Update:</strong> 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!)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload