尝试为我的片段生成绑定 class 时出错
Error trying to generate Binding class for my Fragment
我有以下 XML 文件,它是我的 Fragment 的布局 -
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:padding="15dp"
tools:context=".fragments.DashboardFragment">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/fragment_dashboard_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</layout>
FragmentDashboardBinding
class确实是自动生成的,但是我用不了-
class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
private lateinit var binding : FragmentDashboardBinding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = FragmentDashboardBinding.inflate(inflater, container, false)
return super.onCreateView(inflater, container, savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
}
我在尝试构建项目时遇到了顶部所示的错误,使其无法使用
我遗漏了一些东西。可能是什么?
我已经按照我应该的方式包装了我的布局文件
我目前只需要视图绑定,不需要数据绑定。
请如下更改您的 fragment
:
class DashboardFragment : Fragment() {
private lateinit var binding : FragmentDashboardBinding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_dashboard, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
}
`
我有以下 XML 文件,它是我的 Fragment 的布局 -
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:padding="15dp"
tools:context=".fragments.DashboardFragment">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/fragment_dashboard_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</layout>
FragmentDashboardBinding
class确实是自动生成的,但是我用不了-
class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
private lateinit var binding : FragmentDashboardBinding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = FragmentDashboardBinding.inflate(inflater, container, false)
return super.onCreateView(inflater, container, savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
}
我在尝试构建项目时遇到了顶部所示的错误,使其无法使用
我遗漏了一些东西。可能是什么?
我已经按照我应该的方式包装了我的布局文件
我目前只需要视图绑定,不需要数据绑定。
请如下更改您的 fragment
:
class DashboardFragment : Fragment() {
private lateinit var binding : FragmentDashboardBinding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_dashboard, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
}
`