Hi Klaser,

Have you watched the video that describes ListView adapters at

  http://www.youtube.com/watch?v=N6YdwzAvwOA

and reviewed the Efficient Adapter (View/List 14) of the ApiDemos?

I don't know the details of the problem you are seeing, but it seems
possible that the adapter's view recycler may have some old views when
you are switching views in a single ListView.  If that is the case,
perhaps you could modify the adapter's getView() method to check the
view type of the convert view (e.g., using the ViewHolder class) and
if it is not correct, regenerate (e.g., inflate) a new view.

I hope that helps, but be warned that I certainly am not a ListView
adapter expert (I'm currently struggling with convert view class cast
exceptions).

- Greg




On Jul 29, 7:16 pm, Klaser <[email protected]> wrote:
> I hope someone can share some light on a issue I have with using the
> convertView that is supplied by the BaseAdapter.
>
> The problem is that I have a couple of different listviews in my app.
> When using the convertView with listviews that only shows one type
> everything works fine, and I experience a big performance increase.
> Nice!
>
> However I also have a listview that can show 4 different types of
> views, and I see that getView is supplied with a convertView that is
> of the wrong type. In my BaseAdapter implementation I have added the
> following:
>
> @Override
> public int getItemViewType(int position){
>            LiveStreamElement elem = liveStreamElements.get(position);
>            switch(elem.getElementType()){
>                       case TYPE_A:
>                                  return 0;
>                       case TYPE_B:
>                                  return 1;
>                       case TYPE_C:
>                                  return 2;
>                       case TYPE_D:
>                                  return 3;
>                       default:
>                                  return -1;
>            }
>
> }
>
> @Override
> public int getViewTypeCount(){
>            return 4;
>
> }
>
> From the log I can see that the correct types are returned in
> getItemViewType, but nevertheless the convertView that is supplied in
> the getView method is not guaranteed to be of the right type.
> Ex if I add elements to the list and call notifyDataSetChanged on the
> list, sometimes the views in the list will switch positions. The
> strange thing is that for the most part it seems to work when I
> scroll, but if I reload the list, some elements might have changed
> places. If I change the layout of the screen, ex adds a view beneath
> the listview, which then forces the listview to be redrawn, its
> elements will ‘sometimes’ exchange places too.
> I really hope somebody can share some light on this issue…this thing
> should be rather simple, but it is driving me nuts :D
>
> Any input is much very appreciated :)
>
> Klaser
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to