Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using include as root layout node throws "Error inflating class include" exception

I try to use different list item layout depending on the OS version.

So, I created different layouts associated with conditions. One of them is (in layout/search_result_list_item.xml)

<?xml version="1.0" encoding="utf-8"?>
<include xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    layout="@android:layout/simple_list_item_1">
</include>

it includes the standard "simple_list_item_1".

In my Java code, the layout is associated to the list like this :

    adapter = new SimpleCursorAdapter(getActivity(),
                                      R.layout.search_results_list_item,
                                      null,
                                      from,
                                      to,
                                      0);

When a list item is displayed, the following exception is thrown :

android.view.InflateException: Binary XML file line #2: Error inflating class include
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
   at android.support.v4.widget.ResourceCursorAdapter.newView(ResourceCursorAdapt

What is wrong ? can't be used as a root item ? despite ADT allows it.

like image 902
DenisGL Avatar asked Jan 11 '12 21:01

DenisGL


1 Answers

If anyone else is wondering this is the answer:

<?xml version="1.0" encoding="utf-8"?>
<merge>
    <include xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@android:layout/simple_list_item_1">
    </include>
</merge>
like image 181
Takhion Avatar answered Sep 20 '22 22:09

Takhion