Updating the UI adapter immediately when the value of Int variable is changed inside the ViewModel in Kotlin

i have an interface called IInventoryItem

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>interface IInventoryItem : Parcelable {
val invAuditDetailId: Int
val invAuditItemId: Int
val catalogItemId: Int
val itemName: String
val partNumber: String
val itemUiName: String
val itemConditionCode: String
val itemConditionName: String
val itemLotSerialId: Int
val itemLotSerialNum: String
val expectedQty: Int
val itemCodes: List<IInventoryItemCodes>
var detectedItemRfidCount: Int?
var saved: Boolean?
}
</code>
<code>interface IInventoryItem : Parcelable { val invAuditDetailId: Int val invAuditItemId: Int val catalogItemId: Int val itemName: String val partNumber: String val itemUiName: String val itemConditionCode: String val itemConditionName: String val itemLotSerialId: Int val itemLotSerialNum: String val expectedQty: Int val itemCodes: List<IInventoryItemCodes> var detectedItemRfidCount: Int? var saved: Boolean? } </code>
interface IInventoryItem : Parcelable {

    val invAuditDetailId: Int
    val invAuditItemId: Int
    
    val catalogItemId: Int
    val itemName: String 
    val partNumber: String 
    val itemUiName: String 
    
    val itemConditionCode: String
    val itemConditionName: String 
    
    val itemLotSerialId: Int
    val itemLotSerialNum: String 
    val expectedQty: Int 
    
    val itemCodes: List<IInventoryItemCodes>
    
    var detectedItemRfidCount: Int?
    var saved: Boolean?

}

and i have the adapter

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class InventoryItemsAdapter(
recyclerView: RecyclerView,
list: MutableList<IInventoryItem>
) : BaseRecyclerAdapter<IInventoryItem>(recyclerView, list) {
override fun onDispose() {
}
override fun getViewHolder(p0: Int, p1: LayoutInflater, p2: ViewGroup?): ViewHolder {
return VH(AdapterInventoryingItemCardBinding.inflate(p1, p2, false))
}
inner class VH(viewBinding: ViewBinding) :
BaseRecyclerAdapter<IInventoryItem>.ViewHolder(viewBinding) {
override fun getViewBinding(): AdapterInventoryingItemCardBinding {
return super.getViewBinding() as AdapterInventoryingItemCardBinding
}
override fun setValues(item: c) {
viewBinding.apply {
itemNameTv.text = item.itemName
itemSerialNumberLotTv.text = item.itemLotSerialNum
partNumberTv.text = item.partNumber
itemUiNameTv.text = item.itemUiName
itemConditionNameTv.text = item.itemConditionName
expectedQtyTv.text = item.expectedQty.toString()
detectedQtyTv.text = (item.detectedItemRfidCount ?: 0).toString()
}
}
</code>
<code>class InventoryItemsAdapter( recyclerView: RecyclerView, list: MutableList<IInventoryItem> ) : BaseRecyclerAdapter<IInventoryItem>(recyclerView, list) { override fun onDispose() { } override fun getViewHolder(p0: Int, p1: LayoutInflater, p2: ViewGroup?): ViewHolder { return VH(AdapterInventoryingItemCardBinding.inflate(p1, p2, false)) } inner class VH(viewBinding: ViewBinding) : BaseRecyclerAdapter<IInventoryItem>.ViewHolder(viewBinding) { override fun getViewBinding(): AdapterInventoryingItemCardBinding { return super.getViewBinding() as AdapterInventoryingItemCardBinding } override fun setValues(item: c) { viewBinding.apply { itemNameTv.text = item.itemName itemSerialNumberLotTv.text = item.itemLotSerialNum partNumberTv.text = item.partNumber itemUiNameTv.text = item.itemUiName itemConditionNameTv.text = item.itemConditionName expectedQtyTv.text = item.expectedQty.toString() detectedQtyTv.text = (item.detectedItemRfidCount ?: 0).toString() } } </code>
class InventoryItemsAdapter(
   recyclerView: RecyclerView,
   list: MutableList<IInventoryItem>
   ) : BaseRecyclerAdapter<IInventoryItem>(recyclerView, list) {
   override fun onDispose() {
   }

   override fun getViewHolder(p0: Int, p1: LayoutInflater, p2: ViewGroup?): ViewHolder {
        return VH(AdapterInventoryingItemCardBinding.inflate(p1, p2, false))
    }
    
    inner class VH(viewBinding: ViewBinding) :
        BaseRecyclerAdapter<IInventoryItem>.ViewHolder(viewBinding) {
    
        override fun getViewBinding(): AdapterInventoryingItemCardBinding {
            return super.getViewBinding() as AdapterInventoryingItemCardBinding
        }
        override fun setValues(item: c) {
            viewBinding.apply {
                itemNameTv.text = item.itemName
                itemSerialNumberLotTv.text = item.itemLotSerialNum
                partNumberTv.text = item.partNumber
                itemUiNameTv.text = item.itemUiName
                itemConditionNameTv.text = item.itemConditionName
                expectedQtyTv.text = item.expectedQty.toString()
                detectedQtyTv.text = (item.detectedItemRfidCount ?: 0).toString()

}
}

inside the ViewModel i update the value of item.detectedItemRfidCount, which is

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> val iteminventoryRepository.getInventoryItem(inventoryAudit.invAuditDetailId,codes.invAuditItemId
?: error("must not be null, must set at retrieve items step")
)
for (Detected in detectedItems) {
if (Detected.catalogItemId == item.catalogItemId) {
Detected.detectedItemRfidCount = Detected.detectedItemRfidCount?.plus(1);
}
</code>
<code> val iteminventoryRepository.getInventoryItem(inventoryAudit.invAuditDetailId,codes.invAuditItemId ?: error("must not be null, must set at retrieve items step") ) for (Detected in detectedItems) { if (Detected.catalogItemId == item.catalogItemId) { Detected.detectedItemRfidCount = Detected.detectedItemRfidCount?.plus(1); } </code>
   val iteminventoryRepository.getInventoryItem(inventoryAudit.invAuditDetailId,codes.invAuditItemId
   ?: error("must not be null, must set at retrieve items step")
)
   for (Detected in detectedItems) {
   if (Detected.catalogItemId == item.catalogItemId) {
   Detected.detectedItemRfidCount = Detected.detectedItemRfidCount?.plus(1);
}

i want to update detectedQtyTv in the adapter immediately whenever Detected.detectedItemRfidCount value is changed , keeping the type of detectedItemRfidCount inside IInventoryItem as Int as it is , and detectedItems as MutableList as it is not changing to liveData

i tried to add a new attribute inside IInventoryItem of Type MutableLiveData<Int> , but when retrieving the item from RoomDatabase there is an issue because the return type of inventoryRepository.getInventoryItem(inventoryAudit.invAuditDetailId,codes.invAuditItemId) is IInventoryItem not LiveData

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật