gpt4 book ai didi

android - 如何在回收站 View 中获取某些编辑文本的值(value)?

转载 作者:行者123 更新时间:2023-12-02 13:34:01 26 4
gpt4 key购买 nike

我在回收站 View 中有一些项目,每个项目都有一个编辑文本,我如何从每个编辑文本中获取值并将其传递给前一个 fragment ,我尝试了一些解决方案,但它们都不适合我。
这是我的适配器:


interface OnUpdateData{
fun dataUpdate (data: List<AcceptanceDifferent>?)
}

class EditAcceptDifferentAdapter(private val itemAcceptance: List<DistributionPlanItems>,
private val action: OnUpdateData) :
RecyclerView.Adapter<EditAcceptDifferentAdapter.MainViewHolder>() {

private var selectedItem = mutableSetOf<AcceptanceDifferent>()
private val selectedId = mutableSetOf<Int>()
private lateinit var listData: ArrayList<AcceptanceDifferent>

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): MainViewHolder {
return MainViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.list_edit_different, parent, false)
)
}

override fun getItemCount(): Int {
return itemAcceptance.size
}

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: MainViewHolder,position: Int) {
val items = itemAcceptance[position]
if (!items.expiredDate.isNullOrEmpty()) {
val format2 = "yyyy-MM-dd"
val localeID = Locale("in", "ID")
val simpleDateFormat2 = SimpleDateFormat(format2, localeID)
val date = simpleDateFormat2.parse(items.expiredDate)
holder.expiredDate.text = "Expired Date: ${simpleDateFormat2.format(date)}"
}

holder.batchCode.text = "Batch Code: ${items.inventory?.batchCode}"
holder.medName.text = items.medicine?.name
holder.batchCode.text = items.inventory?.batchCode
listData = ArrayList()

listData.add(AcceptanceDifferent(id = items.distPlanItemId, actualReceivedPackageQuantity = 0))
action.dataUpdate(listData)

}


inner class MainViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
val medName = view.textMedName1
val batchCode = view.tvBatchCode
val expiredDate = view.textMedExpiredDate1
val qty = view.editTextQty
}


}

我已经制作了一个接口(interface)来传递数据,但在我的代码中,它不起作用

谢谢你

最佳答案

您必须注意 EditText 中更改的文本并在那里进行操作,然后通知监听器检查数据。检查以下实现。希望这会帮助你。

// You have to initialize listData outside of onBindViewHolder
listData = ArrayList()

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: MainViewHolder,position: Int) {
val items = itemAcceptance[position]

// Other code here

holder.batchCode.text = "Batch Code: ${items.inventory?.batchCode}"
holder.medName.text = items.medicine?.name
holder.batchCode.text = items.inventory?.batchCode
//listData = ArrayList()

holder.qty.doAfterTextChanged { text ->
val data = listData.find { it.id == items.distPlanItemId }
val value = text?.toString()?.toInt()

if(data == null) {
listData.add(AcceptanceDifferent(id = items.distPlanItemId, actualReceivedPackageQuantity = value))
} else {
data.actualReceivedPackageQuantity = value
}

action.dataUpdate(listData)
}
}

关于android - 如何在回收站 View 中获取某些编辑文本的值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59598940/

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