我有一个Model类的Java实现,该实现被加载到Java类中。我将类转换为Kotlin,但现在参考负载尚未解决
我尝试过URlclassloader,但这会产生更多错误
recyclerview onBindViewHolder中的Java实现
holder.decreaseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(AppDatastore.getPosData().get(position).getProductItemQuantity().equals("1")){
}else {
int count = 1;
count = Integer.parseInt(AppDatastore.getPosData().get(position).getProductItemQuantity());
long id = AppDatastore.getPosData().get(position).getId();
int sum = count - 1;
PosData posData = PosData.load(PosData.class, id);
posData.setProductItemQuantity(sum + "");
posData.save();
}
holder.integerNumber.setText(AppDatastore.getPosData().get(position).getProductItemQuantity());
ipassPos.passPos();
}
});
科特琳课
holder.decreaseButton.setOnClickListener {
if (AppDatastore.posData[position].productItemQuantity == "1") {
} else {
var count = 1
count = Integer.parseInt(AppDatastore.posData[position].productItemQuantity)
val id = AppDatastore.posData[position].id!!
val sum = count - 1
//error occurs here showing unresolved reference load
val posData = PosData.load<PosData>(PosData::class.java, id)
posData.productItemQuantity = sum.toString() + ""
posData.save()
}
holder.integerNumber.setText(AppDatastore.posData[position].productItemQuantity)
ipassPos.passPos()
}
PosData类是
@Table(name = "PosData")
class PosData : Model {
@Column(name = "productItemId")
var productItemId: String? = null
@Column(name = "productItemName")
var productItemName: String? = null
@Column(name = "productItemQuantity")
var productItemQuantity: String? = null
@Column(name = "productItemKind")
var productItemKind: String? = null
@Column(name = "productItemUnitPrice")
var productItemUnitPrice: String? = null
@Column(name = "productItemImage")
var productItemImage: String? = null
constructor() : super() {}
constructor(productItemId: String, productItemName: String, productItemQuantity: String, productItemKind: String, productItemUnitPrice: String, productItemImage: String) {
this.productItemId = productItemId
this.productItemName = productItemName
this.productItemQuantity = productItemQuantity
this.productItemKind = productItemKind
this.productItemUnitPrice = productItemUnitPrice
this.productItemImage = productItemImage
}
fun setPosData(productItemId: String, productItemName: String, productItemQuantity: String, productItemKind: String, productItemUnitPrice: String, productItemImage: String) {
this.productItemId = productItemId
this.productItemName = productItemName
this.productItemQuantity = productItemQuantity
this.productItemKind = productItemKind
this.productItemUnitPrice = productItemUnitPrice
this.productItemImage = productItemImage
}
fun posDataList(): List<PosData> {
return getMany(PosData::class.java, "PosData")
}
}
在Kotlin,我是否有办法做到这一点,或者甚至更好的方法也会有很大帮助
答案 0 :(得分:0)
尝试一下。我正在使用以下课程模型:-
class AddAlertOverViewItem {
@Expose
@SerializedName("email")
lateinit var email: String
@Expose
@SerializedName("alert_type")
lateinit var alertType: String
@Expose
@SerializedName("alert_name")
lateinit var alertName: String
@Expose
@SerializedName("sms")
lateinit var sms: String
@Expose
@SerializedName("alert_id")
lateinit var alertId: String
@Expose
@SerializedName("notification")
lateinit var notification: String
}
在您的适配器类中。像这样访问。
addAlertOverViewItem.sms
addAlertOverViewItem.alertType
addAlertOverViewItem.notification
addAlertOverViewItem.alertName
addAlertOverViewItem
是模型类的对象,sms, alertType, etc.
是模型键的对象,用于访问该键的值。