How to update a text view in the one position of the viewpager

16 Views Asked by At

I am using a viewpager to load the pages with multiple text views. Based on some conditions I have update the text view in the current position of the view pager. How do I do this without having to use the notifyDataSetChanged(), since notifyDataSetChanged() re-instantiates all the pages in the viewpager.

Below is my code :

 override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val binding: ItemBinding =
            ItemBinding.inflate(LayoutInflater.from(container.context))
        setData(position)
        container.addView(binding.root)
        return binding.root
    }

If the position is 1, then I need to update the text view like this :

if (position == 1) binding.title.text = "sample"

How do i do this without notifyDatasetchanged()

0

There are 0 best solutions below