本文介紹了在我的FragmentContainerView對(duì)象中找不到方法getFragment()的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
在XML中我有
<androidx.fragment.app.FragmentContainerView
android:id="@+id/identifications_map_view"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent" />
我想從視圖中獲取片段。documentation建議使用
FragmentContainerView fcv = findViewById(R.id.identifications_map_view);
SupportMapFragment smf = fcv.getFragment()
但Android Studio無法解析符號(hào),如果我按住Ctrl并單擊";FragmentContainerView";,當(dāng)我使用Ctrl+F進(jìn)行搜索時(shí),它不會(huì)顯示getFragment()。
我知道還有另一種方法可以獲得碎片,但我想知道為什么我不能用這種方法。我猜版本有問題,因?yàn)槲业念愃坪跤幸粋€(gè)比文檔舊的版本,例如,還有一個(gè)使用FragmentManager的額外構(gòu)造函數(shù),在文檔中找不到。
這可能是最小的API問題嗎?我有24個(gè)。
謝謝。
推薦答案
1.4.0-alpha01(https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0-alpha01)
如果您使用的是較低版本,它將不在那里。
這篇關(guān)于在我的FragmentContainerView對(duì)象中找不到方法getFragment()的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,