Skip to content Skip to sidebar Skip to footer

Can't Get Parent Position From Convert View

I have a listView that currently displays the names of images along with a thumb of the image beside it. I highlight the selected textBox green onClick, but while scrolling throug

Solution 1:

You need two item view types: one for the selected item and one for all the unselected ones. The adapter will automatically take care of only passing the correct type into your getView method.

At the moment, your adapter knows of only one type of view, so it will just pass any recycled view it has available into your getView method - some of which may still have the green highlight.

You need to implement getItemViewType and getViewTypeCount in your adapter and it will work.

Edit

I'm bored right now so here's what it should be like: :D

protectedstaticfinalint TYPE_NORMAL = 0;
protectedstaticfinalint TYPE_SELECTED = 1;
publicintgetItemViewType(int position){
    return isSelected[position] ? TYPE_SELECTED : TYPE_NORMAL;
}

publicintgetViewTypeCount(){
    return2;
}

Post a Comment for "Can't Get Parent Position From Convert View"