#android #kotlin #android-fragments #fragment #android-viewbinding
Вопрос:
Эй, у меня есть TextInputLayout в моем фрагменте. Я открываю всплывающее окно при нажатии на TextInputEditText. Я добился этого синтетическим способом, но я хочу использовать привязку к виду. Не могли бы вы, пожалуйста, подсказать мне, как правильно это сделать, не используя опции включения макета.
fragment.xml
.....
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="@string/hint"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/header">
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="textCapWords|textNoSuggestions" />
</com.google.android.material.textfield.TextInputLayout>
Фрагмент.кт
class CountryFragment : Fragment() {
private var popupViewArea: View? = null
private var _binding: FragmentBinding? = null
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = FragmentBinding.inflate(inflater, container, false)
setupView()
return binding.root
}
private fun setupView() {
binding.input.setOnClickListener {
showCountriesList()
}
}
private fun showCountriesList() {
if (popupViewArea == null) {
popupViewArea = layoutInflater.inflate(R.layout.pop_list, null)
popupViewArea?.popup_list?.layoutManager =
LinearLayoutManager(context, RecyclerView.VERTICAL, false)
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Я хочу преобразовать pop_list для просмотра привязки. Но я не могу найти правильный способ без тега include
pop_list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="4dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/popup_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingTop="20dp"
android:paddingEnd="30dp"
android:scrollbars="vertical" />
</LinearLayout>