notifyDataSetChanged方法失效的常见原因

来源:互联网 发布:网络运营商密码是什么 编辑:程序博客网 时间:2024/06/04 18:03

举个例子:
if (gridViewAdapter == null) {    gridViewAdapter = new GridViewAdapter(teamPerson, context);
   gv_team_contents.setAdapter(gridViewAdapter);
} gridViewAdapter.setData(teamPerson);
  

notifyDataSetChanged()是在setData中执行的,但是结果是没有效果而且什么变化也没有,

导致很多人在很多处添加notifyDataSetChanged(),最后导致程序崩溃或者卡顿或者仍然没有效果。

最后我是这样解决的

if (gridViewAdapter == null) {     gridViewAdapter = new GridViewAdapter(teamPerson, context);
 }        
gv_team_contents.setAdapter(gridViewAdapter);
gridViewAdapter.setData(teamPerson);
这样就可以了

0 0
原创粉丝点击