ListViewAdaper, el elemento no se vuelve a dibujar según el manejo de getView (XXX)

I'm building a couple of custom ListViews which contains listViewItems whom expands on click. I made my first one without major trouble, and the listViewItems expands correctly on click.

Now i'm building an other ListView, with the difference that it contains more than one kind of item, becuse of this i found it convenient to let the adaper contain a list of views instead of a list of data and creating the views when prompted for them by getView(XX).

Everything works fine except that the items in the new list does not expand until i swap activity back and forth to redraw. I have tested to mimic the implementation in the first listview (with several drawbacks) and with this gets them to redraw correctly.

The main diffrence is these 2 lines, the first one works the second one does not redraw.

return new TransactionChild(context, attrs, transactions.get(position));


return (View) children.get(position); 

What is the best way to fix this? Try to force a redraw on the entire list(on expanding view shifts the rest down...)? or is there something neater i can do with either the ListView or the adapter?

Help would be great :D

preguntado el 23 de abril de 13 a las 13:04

Did you try using an ExpandableListView? -

Yes, when i built the first ListView. I though this was the right approach but the expandablelistView is built for creating something like a folder structure ei showing children of a parent group. I just want to make one view bigger which an expandableListView doesn't do better than the listView :) -

1 Respuestas

You can use an ExpandableListView where the groups don't have any children and have different layouts on group open and closed.

If using a normal ListView, i suggest you make use of the getItemViewType() method of the Adapter, so in this way you keed a list of items normal and clicked and on getView you check the type and change the layout. And on the click listener you change the type of the item clicked and notify for data changed.

Respondido 23 Abr '13, 14:04

If you use the ViewType method, android will handle that for you. Before calling getView, android will call getItemViewType and the convertView send on getView will have the correct type view. So android keeps his cache of different view types. Basically you move your logic to which view to display to getItemViewType and on get view you only get the type, create a view if needed and set the items. - marcio covre

Oh, i had no idea. Thank you i'll try to implement it - SverkerSbrg

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.