gpt4 book ai didi

java - 将模型类加载到 Kotlin 类

转载 作者:行者123 更新时间:2023-12-02 06:04:51 25 4
gpt4 key购买 nike

我有一个 Model 类的 java 实现,正在加载到 Java 类中。我将类转换为 Kotlin,但现在遇到 Unresolved reference 负载

我尝试过 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();

}
});

Kotlin 类

 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 等是模型 key ,用于访问该 key 的值。

关于java - 将模型类加载到 Kotlin 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55948280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com