在导航抽屉关闭之前加载片段 [英] Load Fragment before Navigation Drawer closes

查看:89
本文介绍了在导航抽屉关闭之前加载片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个导航抽屉,我想在导航抽屉关闭之前加载我的片段.当前,该片段与抽屉关闭同时加载,因此,如果该片段很重,则用户界面会挂起一小段时间.

I have implemented a navigation drawer and I want to load my fragment before the navigation drawer closes. Currently, the fragment loads in parallel with the drawer closing, so if the fragment is heavy the user interface hangs for a bit.

我的代码是:

private class DrawerItemClickListener implements
            ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
                 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                 ft.replace(R.id.content_frame, fragmentProfile);
                 ft.commit();
                 drawerLayout.closeDrawer(drawerNaviListView);
        }
    }

如何更改此设置,以便首先看到我的片段加载(在后台),完成加载后,导航抽屉会关闭?

How can I change this so that I see my fragment loading (in background) first and when it has finished loading, the navigation drawer closes?

推荐答案

我的解决方案是在抽屉关闭后加载片段: 实际在onDrawerClosed内部调用loadFragment方法

My solution was to load fragment AFTER drawer is closed: actually call loadFragment method inside onDrawerClosed

 public void onDrawerClosed() {

 // assure the request comes from selecting a menu item, not just closing tab
 if (selectedTab ) 
     selectItem(mSelectedFragment);
     selectedTab = false;
 }

这篇关于在导航抽屉关闭之前加载片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆