我是靠谱客的博主 拉长手链,这篇文章主要介绍解决ViewPager+fragment预加载问题(getItem()两次调用),现在分享给大家,希望可以做个参考。

解决ViewPager+fragment预加载问题(getItem()两次调用)在fragment里面使用

    private View view;

@Override
public
View onCreateView(LayoutInflater inflater, ViewGroup container,
 
Bundle savedInstanceState) {
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if
(parent != null) {
parent.removeView(view);
}
} else {
                  view = inflater.inflate(R.layout.fragment, null);
                  initView();//初始 
                  if(getUserVisibleHint()){
                 //请求网络
                  }
}

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
if
(isVisibleToUser && isVisible()){
 //请求数据 }
super.setUserVisibleHint(isVisibleToUser);}


以上的方法就可以完美的解决预加载问题,或者说请求网络需要弹框多次提示的问题。
我遇到的是第二个...希望可以与大家共享

最后

以上就是拉长手链最近收集整理的关于解决ViewPager+fragment预加载问题(getItem()两次调用)的全部内容,更多相关解决ViewPager+fragment预加载问题(getItem()两次调用)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部