Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么mikepenz';s MaterialDrawer在帐户标题中未显示正确的图标、名称和电子邮件?_Java_Android_Icons_Materialdrawer - Fatal编程技术网

Java 为什么mikepenz';s MaterialDrawer在帐户标题中未显示正确的图标、名称和电子邮件?

Java 为什么mikepenz';s MaterialDrawer在帐户标题中未显示正确的图标、名称和电子邮件?,java,android,icons,materialdrawer,Java,Android,Icons,Materialdrawer,我在我的Android应用程序中使用。该应用程序支持多个同时登录的配置文件,类似于Gmail。因此,当一个配置文件登录时,可以添加另一个配置文件,然后用户可以通过单击标题中的图标来切换活动配置文件 我使用Volley从服务器异步加载配置文件图片。这意味着,当我为登录的配置文件(启动应用程序时)创建ProfileDrawerItems列表时,我会添加一个默认图标。它应该在截击请求返回正确的图标后立即更新。添加新帐户时,同样的逻辑也适用 这是部分工作。正确的图标显示在完整帐户列表中(帐户标题下方)。

我在我的Android应用程序中使用。该应用程序支持多个同时登录的配置文件,类似于Gmail。因此,当一个配置文件登录时,可以添加另一个配置文件,然后用户可以通过单击标题中的图标来切换活动配置文件

我使用Volley从服务器异步加载配置文件图片。这意味着,当我为登录的配置文件(启动应用程序时)创建
ProfileDrawerItems
列表时,我会添加一个默认图标。它应该在截击请求返回正确的图标后立即更新。添加新帐户时,同样的逻辑也适用

这是部分工作。正确的图标显示在完整帐户列表中(帐户标题下方)。但在帐户标题中,我仍然可以看到默认图标:

。这张图片显示了抽屉在添加新的个人资料(“朱比”)后的样子

成功登录后,我使用

getAccountHeader().getProfiles().add(loadProfile(token));
将新配置文件添加到帐户标题<代码>加载配置文件(令牌)如下所示:

   /**
     * Loads and returns the profile for the given token. If a profile already exists in the map profilesByUserId for the token's userID, that profile is updated, otherwise a new profile is created and put into that map.
     * The returned profile might not yet be ready, when this method returns. Some date is loaded asynchronously: Picture, username, user's first and last name.
     *
     * @param token the token, for which the profile should be created or updated
     * @return the profile
     */
    public ProfileDrawerItem loadProfile(Token token) {
        ProfileDrawerItem profile = profilesByUserId.get(token.getUserId());
        if (profile == null) {
            profile = new ProfileDrawerItem();
            profilesByUserId.put(token.getUserId(), profile);
            profile.withIdentifier(token.getId());
            profile.withName(token.getUsername());
            profile.withIcon(R.drawable.default_profile_pic);
        }

        loadProfileData(token);
        loadProfilePic(token);
        return profile;
    }
loadProfileData(Token)
loadProfilePic(Token)
包含截击请求<当请求成功返回时,调用code>onSuccess(…)

loadProfileData(令牌)

我的期望是,在执行了
onSuccess(File)
之后,新的配置文件pic应该显示在帐户标题和标题下的帐户列表中。但是,帐户标题中的pic、姓名和电子邮件不会更新。只有在切换配置文件(执行
getAccountHeader().setActiveProfile(token.getId())
)后,正确的数据和pic才会显示在帐户标题中

在我看来,这似乎是MaterialDrawer的问题,但我不确定。即使是这样,也可能有解决办法

是否有人知道,在更改配置文件后,如何让MaterialDrawer刷新帐户标题,或者如何解决此问题

   /**
     * Loads the profile data (user's name and email address) for the given token and sets it in the appropriate profile. If there is no profile for the given token, nothing happens.
     *
     * @param token token, for which the profile data should be loaded
     */
    private void loadProfileData(final Token token) {

        final ProfileDrawerItem profile = profilesByUserId.get(token.getUserId());
        if (profile == null)
            return;

        // Load name and email address
        Callback<User> callbackUser = new Callback<User>() {
            @Override
            public void onSuccess(User user) {
                profile.withName(String.format("%s %s", user.getFirstName(), user.getLastName()));
                profile.withEmail(user.getUsername());
                profile.withNameShown(true);
            }

            @Override
            public void onError(String error) {
               // not relevant
            }
        };
        loadUserById(token.getUserId(), Source.LOCAL_OVER_REMOTE, callbackUser, token);
    }

    /**
     * Loads the profile pic for the given token and sets it in the appropriate profile. If there is no profile for the given token, nothing happens.
     *
     * @param token token, for which the profile pic should be loaded
     */
    private void loadProfilePic(final Token token) {

        final ProfileDrawerItem profile = profilesByUserId.get(token.getUserId());
        if (profile == null)
            return;

        // Load profile pic
        Callback<File> callbackPic = new Callback<File>() {
            @Override
            public void onSuccess(File profilePic) {
                Bitmap bitmap = FileUtils.createBitmap(profilePic);
                // Crop center square of the bitmap
                int dimension = Math.min(bitmap.getWidth(), bitmap.getHeight());
                bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension);
                profile.withIcon(bitmap);

            }

            @Override
            public void onError(String error) {
                // Not relevant
            }
        };
        loadProfilePicById(token.getUserId(), true, callbackPic, true);
    }