【问题标题】:call notifyDataSetChanged() frequently经常调用 notifyDataSetChanged()
【发布时间】:2013-11-13 03:16:11
【问题描述】:

我的列表视图有一个适配器,然后我需要用 SensorChange 方法中的 notifydatasetchanged 方法刷新它。你知道 SensorChange 方法被频繁快速调用...

过了一会儿,屏幕中的listview消失了,getview方法停止,不再调用。当我删除 notifydatasetchanged 方法时,它很好,但 listview 的项目无法刷新。为什么?

@Override
public void onSensorChanged(SensorEvent evt) {if(mPoiListAdapter != null){
        mPoiListAdapter.notifyDataSetChanged();
    }
}

【问题讨论】:

    标签: android notifydatasetchanged


    【解决方案1】:

    试试这个方法

    Handler mHandler = new Handler();
    
            @Override
                public void onSensorChanged(SensorEvent evt) {
    
                    mHandler.postDelayed(new Runnable() {
    
                        @Override
                        public void run() {
                            if (mPoiListAdapter != null) {
                                mPoiListAdapter.notifyDataSetChanged();
                            }
    
                        }
                    }, 1500);
                }
    

    【讨论】:

    • 你不能重复使用Handler吗?
    • 但是现在,listview 的onItemClickListener 不能工作,只是有时工作。但是如果我删除了 SensorChange 方法中的 notifyDataSetChanged。它工作正常。如何解决这个问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多