`
huaxin803
  • 浏览: 108302 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android 装载器---重启装载器

 
阅读更多

在使用initLoader()方法时,如果指定ID的装载器存在,就使用这个既存的装载器,否则会创建一个新的。但是有些时候你会想要废弃旧的数据并重启装载器。

你可以使用restartLoader()方法来废弃旧的数据。例如,SearchView.OnQueryTextListener的实现就会在用户查询改变时重启装载器。装载器需要重启以便能够使用修正后的搜索过滤器来进行新的查询,如:

public boolean onQueryTextChanged(String newText) {
    // Called when the action bar search text has changed.  Update
    // the search filter, and restart the loader to do a new query
    // with this filter.
    mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
    getLoaderManager().restartLoader(0, null, this);
    return true;
}

注:本人转载系个人觉得翻译的很好,值得收藏,且自己回头看着方便。

如有兴趣请访问作者官方博客http://blog.csdn.net/FireOfStar

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics