Я использую viewPager, где одна вкладка представляет собой представление списка, а одна вкладка представляет собой карту. MapFragment, который я определил следующим образом:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Тогда у меня в функции onViewCreated следующая строка:
val mapFragment = fragmentManager?.findFragmentById(map_fragment.id) as SupportMapFragment
Эта строка выдает ошибку:
android.widget.FrameLayout cannot be cast to com.google.android.gms.maps.SupportMapFragment
Примечание: я использую функцию onViewCreated (), потому что в onCreate () я получаю нулевой указатель на "map_fragment".
My View Pager делает следующее для создания фрагмента:
MapViewFragment.newInstance(location, selection)
У меня есть правильные манифесты для Google Play и карт.
Почему мой фрагмент превращается в FrameLayout? Это ожидаемое поведение?