views:

198

answers:

2

Hi

i'am working on an autogrowing listview. Everytime before i call

    mAdapter.notifyDataSetChanged();

i toggle the latest item on the list with a progress circle.

    /**
    * displays a progress banner instead of the last item.
    * @param reload boolean
    */
    protected void showReloadView(boolean reload){
         View item = mListView.getChildAt(onLastItem);
         //View item = mListView.getAdapter().getView(onLastItem, null, null);
         content = item.findViewById(id.itemContent);
         loading = item.findViewById(id.itemLoading);
         if(reload){
           content.setVisibility(View.GONE);
           loading.setVisibility(View.VISIBLE);
        }else{
           content.setVisibility(View.VISIBLE);
           loading.setVisibility(View.GONE);
   }

My Problem here is that i'am recycling my views as mentioned in the SDK as EfficientAdapter. Therefore my ListView object currently holds no more than 8 items (cause there are no more visible)

The first run is ok, because "onLastItem" is 7 (visible items - 1), but the second run

    ListView.getChildCount() 

returns just 6 items. So why is my ListView getting smaller? Because of Visibility.GONE? Am i doing smth wrong?

I've tried to use the uncommented line as well. My Adapter knows the real size of the list and i can even get the view. But setting the visibility on these views has no effect.

Thx in advance

A: 

So why is my ListView getting smaller? Because of Visibility.GONE?

That'd be my guess, but you'd have to look at the implementation of ListView to know for sure.

FWIW, I took the reverse approach with my EndlessAdapter -- I leave the ListView alone and use a decorating adapter that handles fetching more data.

CommonsWare
A: 

After watching the google IO 09 video i resolved the problem.

Since the Listview contains no more than the visible views i just changed my code to:

View item = mListView.getChildAt(mListView.getChildCount()-1);

Saving the views to a field and after update the dataset i can switch back the layouts. Tested it and works perfect.

Thank you for your time.

dhesse