简体   繁体   中英

MaterialDrawer set selected profile

I use the MaterialDrawer library by Mike Penz.

In my OnCreate, profiles are added to the drawer from a linkedHashMap. When a profile gets selected, the new selected profile is saved in a sharedPreference.

My Question : if I launch the App again, how can I set the profile, whichs name is stored in the sharedPreference, as the selected?

Edit : Without an identifier? Or is this not possible?

The MaterialDrawer requires an identifier given to it's elements so that you can reselect them (and that the Drawer itself can re-select them upon configuration changes) again.

Simply provide any id. You can use something like this:

private static long hashString64Bit(CharSequence str) {
    long result = 0xcbf29ce484222325L;
    final int len = str.length();
    for (int i = 0; i < len; i++) {
        result ^= str.charAt(i);
        result *= 0x100000001b3L;
    }
    return result;
}

To generate an long identifier for your string , or you generate some kind of hashcode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM