The View Binding in Android is heavily advocated as a better replacement for findViewById()
and even Kotlin extensions, but for some reason the most basic functionality as searching usages of a View
by its ID in Layout Editor in Android studio doesn't work.
It doesn't work even in the View Binding Sample in the official Acrh Components Samples repository.
Here we have:
- Xml layout
fragment_blank.xml
with aTextView
with IDtextViewFragment
as following:
<FrameLayout 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"
tools:context=".InflateFragment">
<TextView
android:id="@+id/textViewFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
- Fragment
InflateFragment.kt
which sets text to thisTextView
using view binding:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val binding = FragmentBlankBinding.inflate(inflater, container, false)
fragmentBlankBinding = binding
binding.textViewFragment.text = getString(R.string.hello_from_vb_inflatefragment)
return binding.root
}
So, when I select this ID in the layout editor and do action "Find Usages" from the context menu:
Nothing actually gets found, but we clearly see that we are setting text to this text view in
InflateFragment.kt
Any ideas on how to make such usages searchable by View
ID from the Layout Editor?
Can't believe that such a basic functionality is missing for View Binding.
Android Studio ver 4.0.1
.
Gradle ver 6.6.1
.
Android Gradle Plugin ver 4.0.1