Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If that is all the code you have in the <code>getView</code> method you're not implementing it right:</p> <pre><code>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; } </code></pre> <p>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 <strong>exact</strong> same elements when you scroll up and down because of the recycling. In the <code>getView</code> you should:</p> <ul> <li>Check if the <code>convertView</code> is <code>null</code>: <ul> <li>If it is <code>null</code> it's time to inflate a new <code>View</code> for this <code>GridView</code>'s element. You could also use the holder pattern to cache looking for the composing <code>Views</code>(instead of searching with <code>findViewById</code> everytime)(You use the <code>setTag</code> element for the inflated View but it's a piece of data from the <code>Node</code> data element ?!? What do you plan to do with it?!?)</li> <li>If it isn't <code>null</code> you'll do nothing(or if you implement the holder pattern you would get the tag with the already searched <code>Views</code>)</li> </ul></li> </ul> <p>And this is what you should do in that if/else statement</p> <ul> <li>After the part above you'll populate the <code>Views</code> with data(so they hold the apropriate data for that position).</li> </ul>
 

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