我正在尝试在 Scala 中为 Android 实现一个通用适配器。这些是我的课:
class ScalaAdapter[A <: AnyRef](context: Context, resource: Int, objectsList: ArrayBuffer[A], adapterCb: AfAdapterItemCb) extends BaseAdapter with Filterable {...}
Adapter 的每个用户都必须实现的特征是:
trait AfAdapterItemCb {
def itemCb[A](item: A, view: View) {}
}
我的模型类是:
case class ScheduleItem(name: String, priority: Int)
当我实现回调特征时,我收到与类型参数相关的错误:
private class AdapterCbImpl extends AfAdapterItemCb {
override def itemCb[ScheduleItem](schedule: ScheduleItem, view: View) = {
view.findViewById(R.id.tv_name).asInstanceOf[TextView].setText(schedule.name)
view.findViewById(R.id.tv_priority).asInstanceOf[TextView].setText(schedule.priority.toString)
}
}
当我尝试使用计划对象填充视图时,出现错误:
value name is not a member of type parameter ScheduleItem
value priority is not a member of type parameter ScheduleItem
我无法理解 Manifest 来修复它。有人明白问题是什么吗?