【问题标题】:get profile items from array in mikepenz material drawer从 mikepenz 材料抽屉中的数组中获取配置文件项目
【发布时间】:2020-10-31 21:54:13
【问题描述】:

如您所见,有一些示例配置文件项目绑定到抽屉进行测试(它由 IProfile 制成),但我想从 arraylist<user> 获取它们

这是示例代码:

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("alorma@github.com").withIdentifier(101);
    final IProfile profile3 = new ProfileDrawerItem().withName("Max Muster").withEmail("max.mustermann@gmail.com").withIdentifier(102);
    final IProfile profile4 = new ProfileDrawerItem().withName("Felix House").withEmail("felix.house@gmail.com").withIdentifier(103);
    final IProfile profile5 = new ProfileDrawerItem().withName("Mr. X").withEmail("mister.x.super@gmail.com").withIdentifier(104);
    final IProfile profile6 = new ProfileDrawerItem().withName("Batman").withEmail("batman@gmail.com").withIdentifier(105);

此配置文件将添加到 accountHeaderaddProfiles(profile,profile1,...); 方法中。

但我想从数组中设置配置文件项... 我正在尝试从我的用户那里创建一个 IProfile 数组:

喜欢以这种方式获取个人资料:

 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));
    
      }
    }

但是如何从profiles 数组中获取这些项目并在addProfiles() 方法中使用? 请记住,这个方法来自图书馆,我不能改变它。

【问题讨论】:

    标签: android arrays navigation-drawer profile materialdrawer


    【解决方案1】:

    MaterialDrawer 库公开了一个函数将配置文件配置为vararg 参数,因此使用起来更方便。

    如果您想以 array 的形式提供项目,您可以在 Kotlin 中使用 *(扩展运算符)。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多