Update Inner/Nested RecyclerView from BroadCast Receiver - android

I have a CardViewAdapter that displays a list of folders vertically and then the inner horizontalAdapter displays the contents of the folder horizontally like this:
class CardViewAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var collectionItems : CollectionItems? = null
fun setData(collectionItems : CollectionItems) {
this.collectionItems = collectionItems
this.notifyDataSetChanged()
}
fun updateRow(resourceID : String){
this.collectionItems?.resourceList?.forEach { map ->
map.value.forEach { resourceWState ->
if (resourceWState.component?.uuid == resourceID) {
val index = (this.collectionItems?.resourceList!!.keys).indexOf(map.key)
this.notifyItemChanged(index) // This works but it updates the whole row, not item
}
}
}
}
private inner class ViewHolderCard internal constructor(itemView: View, var resource : ResourceWithState? = null, var tabKeyHolder : Int? = null) : RecyclerView.ViewHolder(itemView) {
internal var fragmentCallback: FragmentCallback? = null
internal var horizontalAdapter: ResourcesByCategoryAdapter? = ResourcesByCategoryAdapter()
internal var mLastClickTime : Long = 0
init {
itemView.inner_recyclerview.layoutManager = LinearLayoutManager(itemView.context, LinearLayoutManager.HORIZONTAL, false)
itemView.inner_recyclerview.isNestedScrollingEnabled = false
itemView.inner_recyclerview.layoutManager!!.isItemPrefetchEnabled = true
itemView.inner_recyclerview.setHasFixedSize(true)
itemView.inner_recyclerview.setItemViewCacheSize(20)
horizontalAdapter?.hasStableIds()
horizontalAdapter?.courseID = courseID
itemView.inner_recyclerview.adapter = horizontalAdapter
fragmentCallback = itemView.context as FragmentCallback
}
internal fun bind(position: Int) {
val dataList = ArrayList(collectionItems!!.resourceList.values)[position]
tabKeyHolder = tabKey
resource = ArrayList(collectionItems!!.resourceList.keys)[position]
val convertToArray : ArrayList<ResourceWithState> = ArrayList()
dataList.toCollection(convertToArray)
horizontalAdapter!!.setData(convertToArray)
horizontalAdapter!!.setCategory(itemView.book_category.text.toString())
// How to call this?
fun updateItem(resourceUUID: String){
horizontalAdapter!!.update(resourceUUID)
}
}
}
And this is the simplified CollectionItems class:
I would like to update the imageView in one of the items inside the folder when the item is downloaded. I already have a broadcast receiver in the fragment that calls the updateRow method. This works but I would like to be able to update the item, not the row. How would I access the method updateItem in the ViewHolder?
// How to call this?
fun updateItem(resourceUUID: String){
horizontalAdapter!!.update(resourceUUID)
}

Related

How to use MutableLiveData<List<String>> as Data of RecyclerView Adapter?

I have one RecyclerView, and if I click one item of it, I want make Data of RecyclerView change.
companion object {
var regionData: MutableLiveData<List<String>> = MutableLiveData()
var smallRegionScreen : Boolean = false
}
So I use MutableLiveData to make Data mutable and keep being observed.
adapter = regionData.value?.let { RegionAdapter(this, it, smallRegionScreen) }!!
I pass regionData.value as Data of Adapter, whose type will be List. And smallRegionScreen is Boolean value.
Since first click of item and second click of item in RecyclerView's taken action will be different, so I differentiate it by this value.
regionDB.get()
.addOnSuccessListener { documents ->
for (document in documents) {
var newArray = ArrayList<String>()
Log.d("리지온1", "$document")
for ((k, v) in document.data) {
regionData.value.add(v.String)
Log.d("리지온", "${regionData.value}")
}
}
adapter.notifyDataSetChanged()
}
binding.regionRecycler.adapter=adapter
binding.regionRecycler.layoutManager= LinearLayoutManager(this)
}
As here, I add item to regionData.value.
But it shows empty Array.
What is problem here?
And My Adapter is below, my process is okay?
class RegionAdapter(private var context: Context, private var regionData: List<String>, private var smallRegionScreen: Boolean): RecyclerView.Adapter<RegionAdapter.RegionViewHolder>() {
var userDB = Firebase.firestore.collection("users")
var userId = Firebase.auth.currentUser?.uid
companion object {
var REGION_RECYCLER_CLICKED = "com.chungchunon.chunchunon_android.REGION_RECYCLER_CLICKED"
}
inner class RegionViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
val regionView: TextView = itemView.findViewById(R.id.regionSelectText)
fun bind (position: Int) {
regionView.text = regionData[position]
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RegionViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_region, parent, false)
return RegionViewHolder(view)
}
override fun onBindViewHolder(holder: RegionViewHolder, position: Int) {
holder.bind(position)
holder.itemView.setOnClickListener { view ->
if(!smallRegionScreen) {
var selectedRegion = regionData[position]
var regionSet = hashMapOf(
"region" to selectedRegion
)
userDB.document("$userId").set(regionSet)
var regionDB = Firebase.firestore.collection("region")
regionDB
.document("4ggk4cR82mz46CjrLg60")
.collection(selectedRegion.toString())
.get()
.addOnSuccessListener { documents ->
for (document in documents) {
for ((k, v) in document.data) {
regionData.plus(v.toString())
}
}
smallRegionScreen = true
}
} else {
var selectedSmallRegion = regionData[position]
var regionSet = hashMapOf(
"smallRegion" to selectedSmallRegion
)
userDB.document("$userId").set(regionSet)
}
}
}
override fun getItemCount(): Int {
return regionData.size
}
}
If you want to add data to your MutableLiveData:
val regionDataList = regionData.value
val templateList = mutableListOf<String>()
regionDataList?.forEach { data ->
templateList.add(data)
}
templateList.add(v.String)
regionData.value = templateList
you can add data in the list like this :-
regionData.value.add(v.toString())

How to set OnclickListener in recyclerView for going another activity

**Hello everyone. I am new in android development. I am using room database and I set data in recyclerView. Now I am trying to Do when I click any recyclerview item then I need to go another activity.Anyone Please help me. **
MainActivity RecyclerView Adding code
private fun setUpListOfDataIntoRecyclerView(registerList:ArrayList<registerEntity>,
registerDao: registerDao){
if(registerList.isNotEmpty()){
var itemAdapter = MainAdapter(registerList)
binding?.rvHappyPlaceList?.layoutManager = LinearLayoutManager(this)
binding?.rvHappyPlaceList?.adapter = itemAdapter
binding?.rvHappyPlaceList?.visibility = View.VISIBLE
binding?.noRecordText?.visibility = View.GONE
}else{
binding?.rvHappyPlaceList?.visibility = View.GONE
binding?.noRecordText?.visibility = View.VISIBLE
}
}
MainAdapter
class MainAdapter(val items: ArrayList<registerEntity>):
RecyclerView.Adapter<MainAdapter.MainHolder>() {
//step 2
private var onClickListener: AdapterView.OnItemClickListener? = null
inner class MainHolder(var binding: ItemHappyPlaceBinding): RecyclerView.
ViewHolder(binding.root) {
val llTitle = binding.tvTitle
val llDescription = binding.tvDescription
var llImage = binding.ivPlaceImage
}
fun setOnClickListener(onClickListener: View.OnContextClickListener){
this.onClickListener = onClickListener
}
override fun onBindViewHolder(holder: MainHolder, position: Int) {
val item = items[position]
holder.llTitle.text = item.title
holder.llDescription.text = item.description
holder.llImage.setImageURI(Uri.parse(item.image))
}
I recommend you replace:
private var onClickListener: AdapterView.OnItemClickListener? = null
with this:
var onItemClick: (() -> Unit)? = null
You can also delete the fun setOnClickListener(..){}
And add in your MainHolder the binding.root.setOnClickListener{} like:
inner class MainHolder(var binding: ItemHappyPlaceBinding): RecyclerView.ViewHolder(binding.root) {
init {
binding.root.setOnClickListener {
onItemClick?.invoke()
}
}
val llTitle = binding.tvTitle
val llDescription = binding.tvDescription
var llImage = binding.ivPlaceImage
}
Or if you prefer u can also add the onItemClick?.invoke() in the onBindViewHolder like:
holder.itemView.setOnClickListener {
onItemClick?.invoke()
}
And then in your activity, in fun setUpListOfDataIntoRecyclerView add:
var itemAdapter = MainAdapter(registerList)
itemAdapter.onItemClick = this::goToActivity()
And also add the goToActivity fun like:
fun goToActivity(){
// launch the activity
}

Refreshing RecyclerView in Kotlin problem

I'm successfully passing data from MainActivity to my recyclerView via adapter, and my view with items is rendering correctly. However, I need to change one member of my item object on click (status), and i wrote a method for that (updateStatus), and it works great, it changes the value and save it to database.
But i cannot refresh my recyclerView, so it could render changed Status attribute. I need to go back on my phone, reenter, and then it renders it correctly. I have tried everything, from notifyDataSetChanged to restarting adapter, no luck. There is something missing and I can't find what.
Here is my MainActivity class
class MainActivity : AppCompatActivity() {
private var posiljkaDAO: PosiljkaDAO? = null
private var dostavnaKnjizicaDAO: DostavnaKnjizicaDAO? = null
private var allItems: ArrayList<DostavnaKnjizicaModel> = arrayListOf()
var adapter = RecycleViewAdapter(allItems)
private var eSifraPosiljke: EditText? = null
#RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_listview)
//get logo
supportActionBar!!.setDisplayShowHomeEnabled(true)
supportActionBar!!.setLogo(R.drawable.logo_bp)
supportActionBar!!.setDisplayUseLogoEnabled(true)
dostavnaKnjizicaDAO = DostavnaKnjizicaDAO(this)
dostavnaKnjizicaDAO?.closeDB()
getAllItems(this)
//connecting adapter and recyclerView
adapter = RecycleViewAdapter(allItems)
recycleView.adapter = adapter
recycleView.layoutManager = LinearLayoutManager(this)
recycleView.setHasFixedSize(true)
eSifraPosiljke = findViewById<EditText>(R.id.eSifraPosiljke)
posiljkaDAO = PosiljkaDAO(this)
}
//method that gets all items from database
private fun getAllItems(context: Context) {
var dostavenFromLOcal = dostavnaKnjizicaDAO?.getAllLocalDostavneKnjizice(context)
if (dostavenFromLOcal != null) {
allItems = dostavenFromLOcal
}
}
//method that changes status of an item
fun changeStatus(context: Context, IdDostavne: Int, statusDostavne: Int) {
dostavnaKnjizicaDAO = DostavnaKnjizicaDAO(context)
dostavnaKnjizicaDAO?.changeStatus(IdDostavne, statusDostavne)
getAllItems(context)
adapter.notifyDataSetChanged()
}
}
and my Adapter class
class RecycleViewAdapter(var dostavneKnjiziceBP: ArrayList<DostavnaKnjizicaModel>)
: RecyclerView.Adapter<RecycleViewAdapter.ViewHolder>() {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
val nazivPrimaoca: TextView = view.txtNazivPrimaoca
val brojPosiljke: TextView = view.txtBrojPosiljke
val statusDostave: TextView = view.txtStatusDostave
val imgMore: ImageView = view.img_more
val context: Context = view.context
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutView = LayoutInflater.from(parent.context).inflate(R.layout.urucenje_posiljke_layout, parent, false)
return ViewHolder(layoutView)
}
override fun getItemCount() = dostavneKnjiziceBP.size
#RequiresApi(Build.VERSION_CODES.KITKAT)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
//New variable to get all modeliPosiljakaBP and their position
var dosKnjizica = dostavneKnjiziceBP[position]
val mainActivity = MainActivity()
//Sending data to layout for display in specific field
if (dosKnjizica.naziv_primaoca != null) {
holder.brojPosiljke.text = "${dosKnjizica.id_dostavna_knjizica}, "
holder.nazivPrimaoca.text = "${dosKnjizica.naziv_primaoca}"
if (dosKnjizica.naziv_primaoca!!.length > 25) {
holder.nazivPrimaoca.text = "${dosKnjizica.naziv_primaoca!!.subSequence(0, 25)}..."
}
} else {
holder.brojPosiljke.text = "${dosKnjizica.id_dostavna_knjizica}"
holder.nazivPrimaoca.text = ""
}
holder.statusDostave.text = "${dosKnjizica.status_dostave_naziv}"
when (dosKnjizica.status_dostave) {
StatusDostaveEnum.Neurucena.value -> {
holder.statusDostave.setTextColor(Color.RED)
}
StatusDostaveEnum.Uruceno.value, StatusDostaveEnum.ZaRejon.value, StatusDostaveEnum.Nadoslano.value, StatusDostaveEnum.Izgubljeno.value -> {
holder.statusDostave.setTextColor(Color.GREEN)
}
StatusDostaveEnum.Obavjesteno.value, StatusDostaveEnum.ZaNarednuDostavu.value -> {
holder.statusDostave.setTextColor(Color.BLUE)
}
StatusDostaveEnum.Retour.value -> {
holder.statusDostave.setTextColor(Color.parseColor("#dda0dd"))
}
}
//Calling menu menu_pregled_drugih_vrsta_posiljke to display menu options on click on three dots
holder.imgMore.setOnClickListener {
val popupMenu = PopupMenu(holder.context, it, Gravity.START)
popupMenu.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.uruci -> {
//calling new activity from second item in dropdown menu
holder.imgMore.context.startActivity(
Intent(holder.imgMore.context, MainActivityInfo::class.java).putExtra(
"Id", dosKnjizica.id_dostavna_knjizica.toString()
)
)
true
}
//here i am calling my changeStatus method from MainActivity
R.id.obavjesti -> {
mainActivity.changeStatus(holder.context, dosKnjizica.id_dostavna_knjizica!!, StatusDostaveEnum.Uruceno.value)
Toast.makeText(holder.context, "obavjesti", Toast.LENGTH_SHORT).show()
true
}
R.id.vrati -> {
Toast.makeText(holder.context, "vrati", Toast.LENGTH_SHORT).show()
true
}
else -> false
}
}
popupMenu.inflate(R.menu.menu_urucenje_posiljke)
popupMenu.show()
}
}
}
Your adapter doesn't have the updated data. Initially, you fetch all data from the database and create an adapter with it: adapter = RecycleViewAdapter(allItems). Afterwards, you are updating the database, calling getAllItems(Context) but you don't pass the data to the adapter.
Add the line adapter.dostavneKnjiziceBP = allItems to the changeStatus method like this:
//method that changes status of an item
fun changeStatus(context: Context, IdDostavne: Int, statusDostavne: Int) {
dostavnaKnjizicaDAO = DostavnaKnjizicaDAO(context)
dostavnaKnjizicaDAO?.changeStatus(IdDostavne, statusDostavne)
getAllItems(context)
adapter.dostavneKnjiziceBP = allItems
adapter.notifyDataSetChanged()
}
Save dostavneKnjiziceBP as a private var inside the adapter and create functions for assigning and updating that ArrayList from within the adapter, using notifyDataSetChanged() everytime a change is done.
class RecycleViewAdapter internal constructor(
context: Context
) : RecyclerView.Adapter<RecycleViewAdapter.ViewHolder>() {
private var items = ArrayList<DostavnaKnjizicaModel>()
// ...
internal fun setItems(items: ArrayList<DostavnaKnjizicaModel>) {
this.items = items
notifyDataSetChanged()
}
override fun getItemCount() = this.items.size
}
Also, try using adapter.notifyItemChanged(updateIndex); if you know the index of the updated item.

How to make delete button to delete recyclerview items in kotlin?

I made selectDelete button on the main activity instead of RecyclerView.
When I click that button, I want to delete the items which are checked.
There is an error that checks the RecyclerView item checkbox and unchecks the item when scrolling.
Activity
class CartViewActivity : AppCompatActivity(), SwipeRefreshLayout.OnRefreshListener {
private val tag = this::class.java.simpleName
lateinit var adapter: CartItemRecyclerAdapter
var itemList: MutableList<CartItemDataVo> = arrayListOf()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_cart_view)
selectDelete.setOnClickListener {
if (checkBox.isChecked) {
*adapter.removeItems()*
}
}
swipeRefreshLo.setOnRefreshListener(this)
itemList.add(CartItemDataVo("item1", 1, 16800, "cart_doll", false))
itemList.add(CartItemDataVo("item2", 1, 16800, "cart_cup", false))
itemList.add(CartItemDataVo("item3", 1, 30000, "cart_perfume", false))
itemList.add(CartItemDataVo("item4", 1, 16800, "cart_fan", false))
adapter = CartItemRecyclerAdapter(this, this, itemList)
recycler_view.adapter = adapter
recycler_view.layoutManager =
androidx.recyclerview.widget.LinearLayoutManager(applicationContext)
}
override fun onRefresh() {
swipeRefreshLo.isRefreshing = false
}
}
Adapter:
class CartItemDataVo(
title: String,
itemNumber: Int,
pointValue: Int,
imageView: String,
CheckBox: Boolean
) {
var title: String = title
var itemNumber: Int = itemNumber
var pointValue: Int = pointValue
var image: String = imageView
var isChecked: Boolean = CheckBox
}
class CartItemRecyclerAdapter(
val context: Context,
private var activity: Activity,
private var dataList: MutableList<CartItemDataVo>
) : RecyclerView.Adapter<CartItemRecyclerAdapter.Holder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(context).inflate(R.layout.cart_item_list, parent, false)
return Holder(view)
}
override fun onBindViewHolder(holder: Holder, position: Int) {
holder?.bind(dataList[position], context)
}
override fun getItemCount(): Int = dataList.size
*#SuppressLint("NewApi")
fun removeItems() {
dataList.removeIf { it.isChecked }
notifyDataSetChanged()
}*
fun toggleItems() {
for (item: CartItemDataVo in dataList) {
var state = item.isChecked
item.isChecked = state.not()
}
notifyDataSetChanged()
}
inner class Holder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
var titleText = itemView?.findViewById(R.id.titleText) as TextView
var temNumerTextt = itemView?.findViewById(R.id.textViewItemNumer) as TextView
var pointValueText = itemView?.findViewById(R.id.pointValueText) as TextView
var imageView = itemView?.findViewById(R.id.imageView) as ImageView
var checkBox = itemView?.findViewById(R.id.checkBox) as CheckBox
fun bind(data: CartItemDataVo, context: Context) {
if (data.image != "") {
val resourceId =
context.resources.getIdentifier(data.image, "drawable", context.packageName)
imageView?.setImageResource(resourceId)
} else {
imageView.setImageResource(R.mipmap.ic_launcher)
}
titleText?.text = data.title
temNumerTextt?.text = data.itemNumber.toString()
pointValueText?.text = data.pointValue.toString() + "P"
if (data.isChecked) {
checkBox.buttonDrawable =
checkBox.context.getDrawable(R.drawable.check_box_active_cs)
val layout = activity?.findViewById(R.id.layoutOrder) as LinearLayout
layout.visibility = View.VISIBLE
} else {
checkBox.buttonDrawable = checkBox.context.getDrawable(R.drawable.check_box_no)
val layout = activity?.findViewById(R.id.layoutOrder) as LinearLayout
layout.visibility = View.GONE
}
checkBox?.setOnClickListener {
if (checkBox.isChecked == data.isChecked) {
checkBox.buttonDrawable = it.context.getDrawable(R.drawable.check_box_active_cs)
val layout = activity?.findViewById(R.id.layoutOrder) as LinearLayout
layout.visibility = View.VISIBLE
} else {
checkBox.buttonDrawable = it.context.getDrawable(R.drawable.check_box_no)
val layout = activity?.findViewById(R.id.layoutOrder) as LinearLayout
layout.visibility = View.GONE
}
}
}
}
}
First of all, replace
var itemList: MutableList<CartItemDataVo> = arrayListOf()
with
val itemList: MutableList<CartItemDataVo> = arrayListOf()
You don't want mutable property, which is also mutable collection at the same time. This is very bad practice.
Same situation in adapter
private var dataList : MutableList<CartItemDataVo>
replace with
private val dataList : MutableList<CartItemDataVo>
Then remove private var activity : Activity from your adapter's constructor. Don't put any references to Activity or Fragment in adapter!
Adapter should be only responsible for displaying list.
If in any case, you need communication between Activity or Fragment and adapter, use interface instead. This is not ViewHolder responsibility to hold reference to parent layout and manipulate it!
val layout = activity?.findViewById(R.id.layoutOrder) as LinearLayout
All lines like below should be removed from ViewHolder. If you need set something which belongs to Activity, based on action on list, use interface.
Finally, in adapter add method which will remove checked items from it:
fun removeItems() {
itemList.removeIf { it.isChecked }
notifyDataSetChanged()
}
Add the following line right after checkBox?.setOnClickListener { (as first line in listener)
data.isChecked = !data.isChecked
And replace
selectDelete.setOnClickListener {
if(checkBox.isChecked){
}
}
with
selectDelete.setOnClickListener {
if(checkBox.isChecked){
adapter?.removeItems()
}
}
Bonus:
read about data class, and use it for CartItemDataVo (don't use CheckBox in constructor),
updateData method can be optimized using DiffUtil for RecyclerView,
it can be improved by modifying data in Activity, not in adapter, so responsible would be moved to better place,
read about SOLID principles,
read about MVVM and MVP design patterns.

Kotlin RecyclerView no adapter attached skipping layout

I don't know what the problem is but same code works fine in java
Here is my adapter class:
class MainAdapter(private val context: Context, private val firebaseVisionlabel: ArrayList<FirebaseVisionLabel>) : RecyclerView.Adapter<CustomViewHolder>() {
override fun getItemCount(): Int {
return firebaseVisionlabel.size
}
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): CustomViewHolder {
val v = LayoutInflater.from(context).inflate(R.layout.list_items,p0,false)
return CustomViewHolder(v)
}
override fun onBindViewHolder(p0: CustomViewHolder, p1: Int) {
val firebaseVisionLabel = firebaseVisionlabel?.get(p1)
val label = firebaseVisionLabel?.label
val confidence =firebaseVisionLabel?.confidence.toString()
p0.itemView.textView.text = label
p0.itemView.confidence.text = confidence
}
}
class CustomViewHolder(v:View) : RecyclerView.ViewHolder(v)
MainActivity: (Global declaration)
var fileUri: Uri? = null
var TAG = "MainActivity"
var firebaseVisionLabels : ArrayList<FirebaseVisionLabel>? = null
In onCreate :
rec_view.layoutManager = LinearLayoutManager(this)
rec_view.setHasFixedSize(true)
Button :
detect_button.setOnClickListener{
imageRecognition()
}
Function :
private fun imageRecognition() {
var bitmap = MediaStore.Images.Media.getBitmap(this.contentResolver, fileUri)
var image = FirebaseVisionImage.fromBitmap(bitmap)
val labeler = FirebaseVision.getInstance().visionLabelDetector
labeler.detectInImage(image)
.addOnSuccessListener { labels ->
for (label in labels) {
val text = label.label
val entityId = label.entityId
val confidence = label.confidence
Log.d("TAG", "$text $confidence") //logcat works
firebaseVisionLabels?.add(label)
//Main problem??
rec_view.adapter = firebaseVisionLabels?.let { MainAdapter(this, it) }
}
}.addOnFailureListener { e ->
// Task failed with an exception
// ...
detect_button.isEnabled = true
Log.d(TAG,e.toString())
}
}
Logcat prints the expected outputs but I don't know what the problem is in recyclerview. I don't want to put bunch of camera and gallery intents codes, they works fine. Thanks for helping.
I solved by changing RecyclerView to BaseAdapter and the parameter to ArrayList. I guess RecyclerView can work same with the Basedapter by changing the parameter private val firebaseVisionlabel: ArrayList<FirebaseVisionLabel> to private val labeltext : ArrayList<String> I think it is a bug between FirebaseVisionLabel and Kotlin
Modified part for MainActivity :
for (label in labels) {
for(i in 1..1){
val text = label.label
val entityId = label.entityId
val confidence = label.confidence
new_list.add(text)
}
list_view.adapter =MainAdapter(this,new_list)

Categories

Resources