android - 从 mikepenz 材料抽屉中的数组中获取配置文件项目
问题描述
如您所见,有一些示例配置文件项目绑定到抽屉进行测试(它由 制成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);
此配置文件将添加到accountHeader
和addProfiles(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
但是如何从Array中获取这些项目并在addProfiles()
方法中使用?请记住,此方法来自库,我无法更改。
解决方案
MaterialDrawer 库公开了一个函数来将配置文件配置为vararg
参数,因此使用起来更方便。
例如,如果您想提供项目,array
可以使用*
Kotlin 中的 (spread operator)。
val myArray = arrayOf(profile, profile2, profile3)
addProfiles(*myArray)
推荐阅读
- pine-script - 在 pine 脚本研究中添加追踪止损
- encryption - 什么是编码错误,即加密时出现 utf-8 错误?
- python - 一种计算 pandas 中顺序事件的解决方案
- javascript - 如何相对于另一个数组上的索引替换数组元素
- c# - 如何从 Blazor .NET Core 项目连接到多个数据库?
- php - 提交后显示 php 代码的 HTML 表单
- elm - 在 elm-lang 的 case 表达式中,管道 `|` 运算符有什么作用?
- jquery - 什么是uuidgen?
- android - android studio 从服务中获取 Activity 对象
- javascript - 更新数组中的用户信息