Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView is recycling items that are still on the screen
    primarykey
    data
    text
    <p>i am using the ListView with a custom object inflated into the getView method.</p> <p>My issue starts when the listview triggers the onItemClicked event, it repaints the items.</p> <p>That is not the issue. The actual issue appears because I am recycling the items that getView gives me.</p> <p>Before I get into that, Here is the Code I am using.</p> <pre><code>public View getView(int position, com.abc.rxcard.Item itemAtPosition, View convertView, ViewGroup parent) { LinearLayout thisItem; //Get the current alert object //Inflate the view if(convertView==null) { thisItem = new LinearLayout(this); String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater vi; vi = (LayoutInflater)this.getSystemService(inflater); vi.inflate(R.layout.offerrow, thisItem, true); } else { thisItem = (LinearLayout) convertView; } Log.d("thisItem","This Item is Index " + position + " " + thisItem.toString() + " " + Integer.toHexString(System.identityHashCode(thisItem))); //Get the text boxes from the listitem.xml file TextView caption =(TextView)thisItem.findViewById(R.id.caption); TextView subText =(TextView)thisItem.findViewById(R.id.subText); ImageView icon = (ImageView)thisItem.findViewById(R.id.offerIcon); //Assign the appropriate data from our alert object above caption.setText(itemAtPosition.text()); subText.setText(itemAtPosition.subText()); MyUtils.setImageFromURLInBackgroundThread(icon, itemAtPosition.icon()); return thisItem; } </code></pre> <p>and the issue arrises when I click on the items. the log output is as follows</p> <pre><code>04-20 14:36:28.402: DEBUG/thisItem(12495): This Item is Index 0 android.widget.LinearLayout@44db1c50 44db1c50 04-20 14:36:28.432: DEBUG/thisItem(12495): This Item is Index 1 android.widget.LinearLayout@44da9038 44da9038 04-20 14:36:28.442: DEBUG/thisItem(12495): This Item is Index 2 android.widget.LinearLayout@44d2ee48 44d2ee48 04-20 14:36:28.932: DEBUG/thisItem(12495): This Item is Index 0 android.widget.LinearLayout@44d2ee48 44d2ee48 04-20 14:36:28.952: DEBUG/thisItem(12495): This Item is Index 1 android.widget.LinearLayout@44da9038 44da9038 04-20 14:36:28.962: DEBUG/thisItem(12495): This Item is Index 2 android.widget.LinearLayout@44db1c50 44db1c50 04-20 14:36:29.622: DEBUG/thisItem(12495): This Item is Index 0 android.widget.LinearLayout@44db1c50 44db1c50 04-20 14:36:29.652: DEBUG/thisItem(12495): This Item is Index 1 android.widget.LinearLayout@44da9038 44da9038 04-20 14:36:29.662: DEBUG/thisItem(12495): This Item is Index 2 android.widget.LinearLayout@44d2ee48 44d2ee48 </code></pre> <p>as you can see the Indexes 0 and 2 are flipping the items back and forth. Now this would not be an issue if the items were not actually on the screen. However when I click on the items (and because the images are loaded in a background thread) My images on items 1 and 3 flip back and forth for every click.</p> <p>This seems like a bad behavior.<br> I am not sure what in the world to do, to fix the problem. Is there a setting or something that I can put on the ListView to stop it from doing that ?</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.
    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