When using ExpandableListView with fragment, exception occurs when inheritance is ListFragment

Use ExpandableListView with Fragment

fragment1.xml


<RelativeLayout 
	xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="30dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp" >
        
    <ExpandableListView
       	android:id="@+id/expListView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:paddingLeft="5dp"
        android:paddingTop="5dp"
        android:background="#003060"
   		android:layout_width="match_parent"
   		android:layout_height="wrap_content"
   		android:clickable="true"
   		android:dividerHeight="3dp" />
</RelativeLayout>

When using ExpandableListView, if the inheritance of the class that implements the fragment is ** ListFragment **,

fragment1.java


public class Fragment1  extends ListFragment {

** onViewCreated ** throws a ** RuntimeException **. (To be exact, an exception is thrown in the superclass, that is, onViewCreated of ListFragment)

 "Content has view with id attribute 'android.R.id.list' that is not a ListView class"

Avoiding exceptions

To avoid this, make the inheritance ** Fragment ** instead of ListFragment.

fragment1.java


public class Fragment1  extends Fragment {

Recommended Posts

When using ExpandableListView with fragment, exception occurs when inheritance is ListFragment
[Unresolved] An exception occurs when an SSH connection is executed using JSch from a Java 6 application.
Unexpected exception when using Java DateTimeFormatter
Using hidden type when PUT with Thymeleaf
When calling API with java, javax.net.ssl.SSLHandshakeException occurs
Java Exception StackTrace is determined when new
Be careful when using rails_semantic_logger with unicorn