get profile items from array in mikepenz material drawer

35 Views Asked by At

as you see there are some sample profile items that are bind to drawer for test(it's made from IProfile),but i want to get them from arraylist<user>

this is sample code:

final IProfile profile = new ProfileDrawerItem().withName(LoginActivity.loggedInUser.get(0).getMobile()+"").withEmail(LoginActivity.loggedInUser.get(0).getResponse()).withIdentifier(100);
    final IProfile profile2 = new ProfileDrawerItem().withName("Bernat Borras").withEmail("[email protected]").withIdentifier(101);
    final IProfile profile3 = new ProfileDrawerItem().withName("Max Muster").withEmail("[email protected]").withIdentifier(102);
    final IProfile profile4 = new ProfileDrawerItem().withName("Felix House").withEmail("[email protected]").withIdentifier(103);
    final IProfile profile5 = new ProfileDrawerItem().withName("Mr. X").withEmail("[email protected]").withIdentifier(104);
    final IProfile profile6 = new ProfileDrawerItem().withName("Batman").withEmail("[email protected]").withIdentifier(105);

that this profiles will add to accountHeader and addProfiles(profile,profile1,...); method.

but i want to set the profile items from an array... i am trying to make An IProfile Array from my users:

like getting profiles this way:

 if(!Arrays.userCars.isEmpty()) {
      for (int i = 0; i <= Arrays.userCars.size(); i++) {
        Arrays.profiles.add(new ProfileDrawerItem()
          .withName(Arrays.userCars.get(i).getName())
          .withEmail(Arrays.userCars.get(i).getCarCompany().toString())
          .withIdentifier(103 + i));
    
      }
    }

but how is possible to get this items from profiles Array and use in addProfiles() method? remember that this method is from library and I can't change it.

1

There are 1 best solutions below

0
mikepenz On

The MaterialDrawer library exposes a function to configure the profiles as vararg arguments, so it's more convenient to use.

In case you want to provide items as array you can use the * (spread operator) in Kotlin for example.

val myArray = arrayOf(profile, profile2, profile3)
addProfiles(*myArray)