在列表视图和列表视图中设置可见性时出现问题基础适配器
我正在研究自动增长的列表视图。每次在我打电话之前,
mAdapter.notifyDataSetChanged();
我都会用进度圈切换列表中的最新项目。
/**
* 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);
}
我的问题是,我正在回收 SDK 中提到的 EfficientAdapter 视图。 因此,我的 ListView 对象当前保存的项目不超过 8 个(因为不再可见)
第一次运行没问题,因为“onLastItem”为 7(可见项目 - 1),但第二次运行
ListView.getChildCount()
仅返回 6 个项目。那么为什么我的 ListView 越来越小呢?因为可见性。消失了? 我做错了吗?
我也尝试过使用未注释的行。我的适配器知道列表的实际大小,我什至可以获得视图。但设置这些视图的可见性没有任何效果。
提前谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的猜测,但您必须查看
ListView
的实现才能确定。FWIW,我用我的
EndlessAdapter
采取了相反的方法 - 我保留ListView
并使用装饰适配器来处理获取更多数据。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 theListView
alone and use a decorating adapter that handles fetching more data.观看 google IO 09 视频后,我解决了该问题。
由于列表视图仅包含可见视图,我只是将代码更改为:
将视图保存到字段,更新数据集后我可以切换回布局。
测试了一下,效果很完美。
感谢您抽出时间。
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:
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.