[英]Load model class to Kotlin class
我有一个Model类的java实现被加载到Java类中。 我将课程转换为Kotlin但现在得到了未解决的参考负载
我尝试过URlclassloader,但这会产生更多错误
recyclelerview 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做到这一点,甚至更好的方式将有很大的帮助
尝试这个。 我正在使用以下类模型: -
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.
的对象,是访问该键值的模型键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.