简体   繁体   English

notifyDataSetChanged方法的BaseAdapter说明

[英]BaseAdapter explanation of the notifyDataSetChanged method

That's my code: 那是我的代码:

public void loadNavigationDrawerItems(){

    adapter.notifyDataSetChanged();
    adapter.setItems();


    //Log.d(TAG, "--> Reload Navigation Drawer");
}

is it correct? 这是正确的吗? or is it better to mod it as this 还是像这样修改它更好

public void loadNavigationDrawerItems(){


    adapter.setItems();
    adapter.notifyDataSetChanged();

    //Log.d(TAG, "--> Reload Navigation Drawer");
}

setItems is a method of the adapter that can load item in the adapter from an external class... My question is if is better to call the notifyDataSetChanged before or after the setItems. setItems是适配器的一种方法,可以从外部类中加载适配器中的项...我的问题是,最好在setItems之前或之后调用notifyDataSetChanged。 Thanks 谢谢

After. 后。 You call it when the changes have finished happening and not before hand. 您可以在更改完成后而不是事先进行调用。 I'm guessing you are using a custom adapter. 我猜您正在使用自定义适配器。 So ideally, the setItems() method should be invoking notifyDataSetChanged() itself instead of having to rely on it happening externally. 因此,理想情况下, setItems()方法应本身调用notifyDataSetChanged()而不必依赖于外部发生的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM