如何在Android中将viewmodel绑定到gridView?

问题描述 投票:0回答:1

我在活动中具有一个自定义适配器类的gridView,我无法弄清楚如何将视图模型绑定到活动的gridView。

android android-adapter android-gridview android-viewmodel android-mvvm
1个回答
0
投票

<layout></layout>放入行文件中,然后可以设置ViewModel名称的变量名。现在,您可以在适配器的getViewHolder中设置视图的膨胀,如下所示。

mTaskCustomLayoutBinding =
            DataBindingUtil.inflate(inflater, R.layout.task_custom_layout, parent, false)
        return MyViewHolder(this!!.mTaskCustomLayoutBinding!!)
© www.soinside.com 2019 - 2024. All rights reserved.