0

我正在创建一个应用程序,它可以过滤联系人,但遗憾android.view.InflateException的是在启动带有联系人列表的片段时被抛出,该片段QuickContactBadge对单个联系人使用重视图。

有类似的问题Fragment view inflating error: Resource is not a drawable on SO 有几种可能的解决方案。但是,他们没有对这个问题做出任何澄清。任何提议的决定仍然存在运行时膨胀错误。具体情况请查看下方。

来自 Logcat 的 Android 运行时错误

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)
    ...

QuickContactBadge 膨胀的代码片段

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);

            ...
        }

        ...
    }

    ...
}

联系人项目布局 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>
4

0 回答 0