0

I am trying to use executePendingBinding with gridView adapter. On some data change the binding is not executing at first but other UI operations are being executed before that. How do I prevent that. Here is my ImageAdapter :

class ImageAdapter constructor(
    private val mContext: Context,
    private val resource_layout: Int,
    private val viewModelList: ArrayList<ProfileViewModel>
) :
    ArrayAdapter<ImageAdapter.ViewHolder>(mContext, resource_layout) {

    private lateinit var imageCardBinding: ImageCardBinding

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        var convertView = convertView

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(resource_layout, null)
            imageCardBinding = DataBindingUtil.bind(convertView)!!
            convertView.tag = position
            convertView.tag = imageCardBinding
        } else imageCardBinding = convertView.tag as ImageCardBinding

        imageCardBinding.profileViewModel = viewModelList[position]
        imageCardBinding.executePendingBindings()

        return imageCardBinding.root
    }

    override fun getCount(): Int {
        return viewModelList.size
    }

    inner class ViewHolder
}

And on some value successfully changed I am executing this:

        gridView.get(imageGridPosition).grid_item_progress.visibility = View.GONE
        profile_root.snackBar("Image is set ! You can tap on the image to change it")

But as the binding is not done immediately the gridView.size is 0 and if I comment out the line the picture is set some times later but snackbar is showing before that. Can it be fixed with executePendingBinding(), if that then how to do that ? or is there any other way?

SuvodipMondal
  • 87
  • 1
  • 8

0 Answers0