Justin Yue
01/06/2023, 12:08 AMAndroidView
, but when I run my app, my custom view does not appear. I was thinking perhaps passing in null for the root
paramater might be problematic for LayoutInflater.from(context).finflate(R.layout.view_visualization, null, false)
. Normally, I would call rootView
instead, but that just returns my custom view. Is there a way to instead have the root be the composable that calls this custom view?mattinger
01/06/2023, 2:38 AMmattinger
01/06/2023, 2:51 AMmattinger
01/06/2023, 2:53 AMmattinger
01/06/2023, 2:55 AMAndroidViewBinding(
factory = { inflater, parent, attachToParent ->
inflater.inflate(R.layout.view_visualization, parent, attachToParent)
}
)
mattinger
01/06/2023, 2:56 AMAndroidViewBinding(factory=ViewVisualization::inflate)
Justin Yue
01/06/2023, 3:03 AMError inflating class androix.fragment.app.FragmentContainerView
. Perhaps it's because I didn't insert the FragmentContainerView
properly in my xml file?
Here's the relevant code.
@Composable
fun VizSection(onBack: () -> Unit) {
val TAG = "VizSection"
val fragmentContainerView = FragmentContainerView(LocalContext.current)
Column(modifier = Modifier.fillMaxWidth()) {
HomeNavBar(title = R.string.visualization_title, false, { onBack() }) {
onBack()
}
AndroidViewBinding(FragmentVisualizationBinding::inflate) {
Log.d(TAG, "compose: Viz Section is called")
val vizFragment = fragmentContainerView.getFragment<VisualizationFragment>()
}
}
}
XML File:
<RelativeLayout 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=".ui.visualization.VisualizationFragment"
android:name="com.radgard.lara.ui.visualization.VisualizationFragment">
<androidx.fragment.app.FragmentContainerView
xmlns:android="<http://schemas.android.com/apk/res/android>"
android:id="@+id/fragment_container_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:name="com.radgard.lara.ui.visualization.VisualizationFragment">
</androidx.fragment.app.FragmentContainerView>
<android.opengl.GLSurfaceView
android:id="@+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Plz work"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_margin="25dp"/>
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_margin="25dp"
android:src="@drawable/ic_settings"
android:background="@android:color/transparent"/>
</RelativeLayout>
mattinger
01/06/2023, 3:07 AMmattinger
01/06/2023, 3:12 AMval fragmentContainerView = FragmentContainerView(LocalContext.current)
mattinger
01/06/2023, 3:12 AMJustin Yue
01/06/2023, 3:20 AMfragmentContainerView
to create my fragment bc that's where I would run my ARCore-related codemattinger
01/06/2023, 3:30 AMmattinger
01/06/2023, 3:31 AMmattinger
01/06/2023, 3:33 AMmattinger
01/06/2023, 3:34 AMandroid.view.InflateException: Binary XML file line #12 in com.example.material3test:layout/layout_test: Binary XML file line #12 in com.example.material3test:layout/layout_test: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #12 in com.example.material3test:layout/layout_test: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
mattinger
01/06/2023, 3:35 AMCaused by: java.lang.UnsupportedOperationException: FragmentContainerView must be within a FragmentActivity to use android:name="androidx.fragment.app.Fragment"
Justin Yue
01/06/2023, 3:36 AMIan Lake
01/06/2023, 5:30 AMError inflating class androix.fragment.app.FragmentContainerView
always, always, always points to another exception farther down. You'll need to include that stack trace for anyone to be able to help