Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue when fast scroll a listview?
    primarykey
    data
    text
    <p>I am working on a small project where I create a <code>listview</code> bound to an ArrayAdapter. In the <code>getView()</code> function of ArrayAdapter, I do a loading of images from web <code>urls</code> on thread, and set them to list items(based on position off course, so <code>url[0]</code> image is set to <code>list_item[0]</code> etc). It all seems to work well.</p> <p>However when I was testing the app, I noticed that if I wait my listview to fully display, then perform a fast scroll back and forth, I see sometimes <strong>the image on one list item is misplaced on other</strong>(like being in an intermediate state). However it's not going away until i scroll the wrongly-displayed-item out of screen and then back.</p> <p>Has anyone met this kind of problem before? I do not know if it relates to my loading web <code>url</code> using thread, or maybe loading image from local resource folder can have the same issue.</p> <p>This actually leads to a question i have about <code>getView()</code> function. I think the logic is correct in my <code>getView()</code> 'cause it's as simple as a binding of url to view based on position. And whenever <code>getView()</code> get a chance to be called, like when I scroll an item out of screen then back, it will make the list item display correctly.</p> <p>The thing I do not get is how to explain the issue that happened(like an intermediate state), and how to avoid it when writing code?</p> <p>Any one could help?</p> <p>I paste my adapter code piece below, but i think the question maybe a general one:</p> <pre><code> @Override public View getView(int position, View v, ViewGroup parent) { ViewHolder viewHolder = null; if (v == null) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(layoutResourceId, parent, false); viewHolder = new ViewHolder(); viewHolder.title = (TextView) v.findViewById(R.id.title); viewHolder.description = (TextView) v.findViewById(R.id.description); viewHolder.image = (ImageView) v.findViewById(R.id.image); v.setTag(viewHolder); } else { viewHolder = (ViewHolder) v.getTag(); } listItem item = items[position]; //items is some global array //passed in to ArrayAdapter constructor if (item != null) { viewHolder.title.setText(item.title); viewHolder.description.setText(item.description); if (!(item.imageHref).equalsIgnoreCase("null")) { mDrawableManager.fetchDrawableOnThread(item.imageHref, viewHolder.image); } else { viewHolder.image.setImageDrawable(null); } } return v; } } static class ViewHolder { TextView title; TextView description; ImageView image; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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