导航抽屉列表

时间:2016-01-12 14:04:27

标签: android dynamic navigation-drawer

我有一个导航抽屉,使用下面的类创建显示的itens:

public class Config {

public static List<NavItem> configuration() {

    List<NavItem> i = new ArrayList<NavItem>();

    //DONT MODIFY ABOVE THIS LINE

    //Some sample content is added below, please refer to your documentation for more information about configuring this file properly
    i.add(new NavItem("Bombeiro", R.drawable.ic_action_favorite, NavItem.SECTION));
    i.add(new NavItem("Home", R.drawable.ic_details, NavItem.ITEM, HomeFragment.class, null));
    i.add(new NavItem("Nova Vistoria", R.drawable.ic_vistoria_blue, NavItem.ITEM, VistoriaActivity.class));

    //It's suggested to not change the content below this line

    i.add(new NavItem("Opções", R.drawable.ic_action_settings, NavItem.SECTION));
    i.add(new NavItem("Importar dados", R.drawable.ic_action_favorite, NavItem.EXTRA, SyncImportFragment.class, null));
    i.add(new NavItem("Sincronizar Vistoria", R.drawable.ic_action_favorite, NavItem.EXTRA, SyncExportFragment.class, null));
    i.add(new NavItem("Salvar Vistoria", R.drawable.ic_action_favorite, NavItem.EXTRA, SaveFragment.class, null));

    //DONT MODIFY BELOW THIS LINE

    return i;

}

}

我正在尝试将其更改为动态工作。因此,我尝试用其他选项创建一个新文件,然后调用它;但是,它没有改变清单。

有人可以给我任何提示吗?

谢谢

修改

这是用于获取itens列表的代码:

private List<NavItem> getConfiguration(){
    if (null == mConfiguration){
        mConfiguration = Config.configuration();

        boolean newDrawer = getResources().getBoolean(R.bool.newdrawer);

        if (newDrawer == true){
            mConfiguration.add(0, new NavItem("Header", NavItem.TOP));
        }
    }

    return mConfiguration;
}

我试着像这样制作一个setConfiguration:

private List<NavItem> setConfiguration(config){
    if (null != mConfiguration){
        mConfiguration = config.configuration();

        boolean newDrawer = getResources().getBoolean(R.bool.newdrawer);

        if (newDrawer == true){
            mConfiguration.add(0, new NavItem("Header", NavItem.TOP));
        }
    }

    return mConfiguration;
}

当我点击按钮时,它会调用。

0 个答案:

没有答案