我的apk被上传到alpha频道,我的产品被创建,购买按钮(如果有效的话)。
我想展示几款可在回收服务中购买的产品。这些东西对我有用。
在我的
myadapter.kt
文件我有以下变量
var p = ArrayList<String>()
以及功能:
fun queryskudetails() {
billingClient = BillingClient.newBuilder(context).setListener(this).build()
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {
Log.i("Disconnected", "billing client")
}
override fun onBillingSetupFinished(responseCode: Int) {
billingClient.let { billingClient ->
val skulist = ArrayList<String>()
skulist.add("books")
skulist.add("pens")
skulist.add("keychains")
val params = SkuDetailsParams.newBuilder()
params.setSkusList(skulist).setType(BillingClient.SkuType.INAPP)
billingClient.querySkuDetailsAsync(params.build(), { responseCode, skuDetailsList ->
if (responseCode == BillingClient.BillingResponse.OK && skuDetailsList != null) {
for (skuDetails in skuDetailsList) {
val sku = skuDetails.sku
val price = skuDetails.price
Log.i("skudetails", sku)
Log.i("skuprice", price)
hashMap[sku] = price
println("===== price and sku ======")
println(price)
println(sku)
println("===== /proce and sku ======")
// add price to array p1 (defined as a global variable)
p1.add(price)
}
p = precios
}
})
}
}
})
}
onBindViewHolder
在这里我将价格和标题分配给一个文本视图:
override fun onBindViewHolder(holder: Vholder, position: Int) {
queryskudetails()
print("-----Here array price print [] -----")
println (p)
var text: String = array[position]
Log.i("text", text)
holder.textView.text = text
holder.Price.text = hashMap[text.toLowerCase()].toString() // this does not work for me, retun null
Log.i("price", hashMap["books"].toString())
println(hashMap[array[position]]) // retunr null
holder.btn.setOnClickListener(View.OnClickListener {
Log.i("button", text.toLowerCase())
var skuid = hashMap2[text]
val flowParams = BillingFlowParams.newBuilder()
.setSku(text.toLowerCase())
.setType(BillingClient.SkuType.INAPP)
.build()
val responseCode = billingClient.launchBillingFlow(context as Activity?, flowParams)
})
}
当我在文本视图中显示价格时,以下代码对我不起作用:
holder.Price.text = hashMap[text.toLowerCase()].toString()
哪里
Price
是
var Price: TextView = itemView.findViewById(R.id.price)
作为第二种选择,我尝试使用矩阵
p1
queryskudetails ()
函数,但返回空。
p1号
?