开发者

Problem with setting visibility in a Listview & BaseAdapter

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.findV开发者_如何学JAVAiewById(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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜