Android - 可以在自定义适配器中混合类型吗?
对于适配器,您可以为其提供某种类型的对象/类型集合,例如
List<MyObject> myList = new ArrayList<MyObject>;
myCustomAdapter adapter = new myCustomAdapter(this, myList);
如果您想在适配器中使用多种类型的对象,该怎么办。因此,适配器中的某些项目将是一个对象,而其他项目将是不同的对象。你会怎样去做这样的事情呢?
For an Adapter, you would give it some type of collection of objects/types, like
List<MyObject> myList = new ArrayList<MyObject>;
myCustomAdapter adapter = new myCustomAdapter(this, myList);
What if you wanted to use multiple types of Objects in your adapter. So certain items in the adapter would be one object while other items would be different objects. How would you go about doing something like that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您可以控制
myCustomAdapter
中的代码?如果是这样,您可以创建一个所有对象将共享的接口,使您的适配器通用并将类型参数限制为该接口。I assume that you have control over the code within
myCustomAdapter
? If so, you can create an interface that all of your objects will share, make your adapter generic and constrain the type parameter to that interface.