I\'m having a really weird problem. I have a common fragment that is added in almost every activity of my app. This fragment shows a small version of the player bar. So it l
Oh my God, I can't beleive it. I solved my problem just setting the ID of the fragment that was having problem.
Now, the XML's layout of the Activity is like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:name="com.soongz.ui.fragment.ListaDeMusicasFragment"
android:id="@+id/lista_de_musicas_fragment"
style="?layoutListViewMusicas" />
<fragment
android:id="@+id/player_reduzido_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:name="com.soongz.ui.fragment.PlayerReduzidoFragment"/>
</LinearLayout>
I don't know why. It must be a bug.
For future reference, I found that my issue lay in my fragment's onCreateView()
method. I had the following:
private lateinit var containingView : View
// ......
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
containingView = inflater.inflate(R.layout.my_fragment_layout, container, false)
return view
}
.....which caused an error because while I was inflating the layout to containingView
, I was actually returning view
(which just happens to be a property of the fragment class of the correct type). The corrected code is this:
private lateinit var containingView : View
// ......
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
containingView = inflater.inflate(R.layout.my_fragment_layout, container, false)
return containingView
}