Makarele
Makarele

Reputation: 59

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?

Upvotes: 0

Views: 76

Answers (1)

mikepenz
mikepenz

Reputation: 12868

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.

Upvotes: 1

Related Questions