ViewGroup中ListView数据使用notifyDataSetChanged不能更新数据的问题!

来源:互联网 发布:excel如何加载宏 mac 编辑:程序博客网 时间:2024/05/16 17:46

正在做一个包含滑动菜单的应用。界面包含两部分,隐藏的菜单和listview主界面。使用viewgroup实现。

但是问题是Listview实现滑动删除时,使用notifyDataSetChanged不能立即更新数据。

纠结很久终于发现问题出在Viewgroup中的onLayout方法。

@Override   
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// if (changed) {
menu_view = getChildAt(0);
content_view = getChildAt(1);


content_view.measure(0, 0);
content_view.layout(0, 0, getWidth(), getHeight());
// }
}

住掉onLayout中的if(changed)即可。

具体原因正在分析源码...