Materialdrawer: Multiple profiles in drawer dynamically

Created on 16 Jun 2016  路  7Comments  路  Source: mikepenz/MaterialDrawer

Hi I am trying to add multiple profiles in drawer as user may login with different credentials.Here, I don't know the exact number of users.But i am kinda stuck here.Also when user opens app next time I will have to get all the list of logged in users saved in database.Can you suggest any idea?

question

Most helpful comment

@riten7 you want to mix an array with single elements?

Here's the javadoc. The API allows you to add an array, or single entries.
http://javadoc.io/doc/com.mikepenz/materialdrawer/5.2.9

You can always split up the builder.

AccountHeaderBuilder builder = new AccountHeaderBuilder().
..
builder.addProfiles(...);
builder.addProfiles(...);
..
builder.build();

All 7 comments

@riten7 saving and restoring the users is something you have to implement. This is nothing library specific.

Adding profiles can be done via the API of the AccountHeader at any time. And you can also just provide a flexible number of profiles during AccountHeader creation

I have already retrieved the users from db and I have implemented adding an profile dynamically in the drawer too.My question is or I am just having problem on how to list all the profiles in the drawer retrieved from database in the Account Header...

@riten7 the AccountHeader will at max show 1 active profile, and 3 small preview icons of previous used profiles. And when you click the list you will see the rest of the accounts.

So what's your issue?

For now I have like one profile like this:

`final IProfile profile = new ProfileDrawerItem().withEmail("[email protected]").withName("Free Trial").withIdentifier(100);

    headerResult = new AccountHeaderBuilder()
            .withActivity(this)
            .withHeaderBackground(R.drawable.header)
            .addProfiles(
                    profile,
                    new ProfileSettingDrawerItem().withName("Add Account").withDescription("Add Account").withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add).actionBarSize().paddingDp(5).colorRes(R.color.material_drawer_primary_text)).withIdentifier(321),
                    new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings).withIdentifier(123)
            )`

Now I have array list of profiles from database and how to load arraylist of profiles in addProfile section..

i am trying this code

.addProfiles(
                        profiles,
                        new ProfileSettingDrawerItem().withName("Add Account").withDescription("Add Account").withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add).actionBarSize().paddingDp(5).colorRes(R.color.material_drawer_primary_text)).withIdentifier(321),
                        new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings).withIdentifier(123)
                )
 public List<IProfile> getProfiles(){

        List<UserData>list = databaseHandler.getUserList();
        profiles = new ArrayList<>();

        if (!list.isEmpty()) {
            for(int i=0; i < list.size(); i++) {
                String email = list.get(i).getEmail();
                String name = list.get(i).getFirstName();
                profiles.add(new ProfileDrawerItem().withEmail(email).withName(name));
            }
        }
        return profiles;
    }

But this shos error.. i m stuck here.. can you help ??

@riten7 you want to mix an array with single elements?

Here's the javadoc. The API allows you to add an array, or single entries.
http://javadoc.io/doc/com.mikepenz/materialdrawer/5.2.9

You can always split up the builder.

AccountHeaderBuilder builder = new AccountHeaderBuilder().
..
builder.addProfiles(...);
builder.addProfiles(...);
..
builder.build();
Was this page helpful?
0 / 5 - 0 ratings

Related issues

fuentepa picture fuentepa  路  3Comments

ghost picture ghost  路  3Comments

jd-alexander picture jd-alexander  路  4Comments

armoun picture armoun  路  3Comments

Erwinstein picture Erwinstein  路  3Comments