我刚刚将Android Studio更新为3.6,并在项目中启用了视图绑定,并且可以在片段中使用视图绑定。
我有ListItemAdapter类,它是BaseExpandableListAdapter的子类,我也想对该类使用View Binding。似乎不支持适配器类?
如上所述。我正在使用ExpandableListView。下面是在ExpandableListView适配器类内部膨胀GroupView和ChildView的代码。
现在我正在使用KotlinX.android.synthetic
override fun getGroupView(
groupPosition: Int,
isExpanded: Boolean,
convertView: View?,
parent: ViewGroup?
): View {
var convertView: View? = convertView
?: return context.layoutInflater.inflate(R.layout.list_item_parent_sidemenu, null)
convertView!!.imgGroupIndicatorIcon.isSelected = isExpanded
var headerTitle = getGroup(groupPosition) as String
convertView!!.txtSideMenuParent.text = headerTitle
return convertView!!
}
override fun getChildView(
groupPosition: Int,
childPosition: Int,
isLastChild: Boolean,
convertView: View?,
parent: ViewGroup?
): View {
var convertView: View? = convertView
?: return context.layoutInflater.inflate(R.layout.list_item_child_sidemenu, null)
var childText = getChild(groupPosition, childPosition) as String
convertView!!.txtSideMenuChild.text = childText
return convertView!!
}
enter code here
val视图= BistItemParentSidemenuBinding.inflate(LayoutInflater.from(parent.context),父,false)。root
上面的内容应该代替
var convertView:视图? = convertView?:返回context.layoutInflater.inflate(R.layout.list_item_child_sidemenu,null)