Right so let's say my adapter looks like this, and by default I always
have 5 cows to render, and 0 horses to render. Cows and Horses each
require a different view type:

public class MyAdapter extends BaseAdapter {
  ArrayList<Horse> mHorses;
  ArrayList<Cow> mCows;

  public MyAdapter() {
    mHorses = new ArrayList<Horse>();
    mCows = new ArrayList<Cow>();
    for (int i = 0; i < 5; i++) { mCows.add(new Cow()); }
  }

  public void addHorse(Horse h) {
    mHorses.add(h);
  }

  @Override
  public int getViewTypeCount() {
    int count = 0;
    if (mHorses.size() > 0 {
      count++;
    }
    if (mCows.size() > 0) {
      count+;
    }
    return count;
  }
}

at some point, I may add a Horse, so now the adapter needs to know
that I have 2 different view types instead of 1. So 'internally', it
would be nice if I could force the adapter to re-call
getViewTypeCount(), something like:

  public void addHorse(Horse h) {
    mHorses.add(h);
    this.pleaseReCallGetViewTypeCount();
  }

this example is silly, but I hope it illustrates the problem. What I'm
doing right now is this instead:

  mAdapter.addHorse(new Horse());
  mListView.setAdapter(mAdapter);

Thanks

On Mar 2, 11:28 am, Mark Murphy <mmur...@commonsware.com> wrote:
> Mark Wyszomierski wrote:
> > Hi,
>
> > I have a list adapter extended from BaseAdapter. Is there any way to
> > get getViewTypeCount() to be called besides the following:
>
> >   mMyListView.setAdapter(mMyAdapter): // gets fired as a result of
> > setAdapter().
>
> > Is there any other way to trigger this? The docs for
> > BaseAdapter.getViewTypeCount() say:
>
> >   "This method will only be called when when[sic] the adapter is set
> > on the the[sic] AdapterView."
>
> The AdapterView is the one that needs the getViewTypeCount() value, so
> it can maintain appropriate object pools.
>
> > I'm just seeing if there is a way to trigger it inside my custom list
> > adapter class so the external users (activities) don't need to worry
> > about it.
>
> What does that mean?
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android Consulting/App Development:http://commonsware.com/consulting

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to