0

I am creating an app that makes contacts filtering but sadly android.view.InflateExceptionis thrown in time of launching a fragment with contact list which uses heavy QuickContactBadge view for single contact.

There are similar problem Fragment view inflating error: Resource is not a drawable on SO with several possible solutions presented. However they do not bring any clarification to the issue. There are still runtime inflation error with any of proposed decisions. The case specific please check below.

Android runtime error from Logcat:

android.view.InflateException: Binary XML file line #5: Error inflating class android.widget.QuickContactBadge
    at android.view.LayoutInflater.createView(LayoutInflater.java:626)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    at com.contactexctractor.ContactFragment$ContactsAdapter.newView(ContactFragment.java:127)
    ...

Code snippet of QuickContactBadge inflation:

public class ContactFragment extends Fragment implements EventSubscriber, LoaderManager.LoaderCallbacks<Cursor>
{
    ...

    private class ContactsAdapter extends CursorAdapter implements SectionIndexer   {
        private LayoutInflater mInflater; 

        /**
         * Instantiates a new Contacts Adapter.
         * @param context A context that has access to the app's layout.
         */
        public ContactsAdapter(Context context) {
            super(context, null, 0);

            // Stores inflater for use later
            mInflater = LayoutInflater.from(context);

            ...
        }

        /**
         * Overrides newView() to inflate the list item views.
         */
        @Override
        public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
            // Inflates the contact list item layout.
            final View itemLayout = mInflater.inflate(R.layout.contacts_item, viewGroup, false);

            ...
        }

        ...
    }

    ...
}

Contact item layout XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight" >

    <QuickContactBadge
        android:id="@android:id/contact_icon"
        android:layout_width="?android:attr/listPreferredItemHeight"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:src="@drawable/ic_contact_picture_holo_light" />

    <TextView
        android:id="@android:id/contact_bio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@android:id/contact_icon" />

</RelativeLayout>
Community
  • 1
  • 1
Yehor Nemov
  • 907
  • 2
  • 16
  • 31

0 Answers0