Question

I'm trying to implement a library called PinnedHeaderListView in my fragment to have a Pinned header for my listview.

This is what I've came up

public class MyFragment extends Fragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.main, container, false);

    PinnedHeaderListView listview= (PinnedHeaderListView) v.findViewById(R.id.pinnedListView);
    MyFragmentAdapter adapter = new MyFragmentAdapter ();


    LinearLayout header1 = (LinearLayout)inflater.inflate(R.layout.list_item, null);
    ((TextView) header1.findViewById(R.id.textItem)).setText("HEADER 1");

    LinearLayout header2 = (LinearLayout) inflater.inflate(R.layout.list_item, null);
    ((TextView) header2.findViewById(R.id.textItem)).setText("HEADER 2");

    LinearLayout footer = (LinearLayout) inflater.inflate(R.layout.list_item, null);
    ((TextView) footer.findViewById(R.id.textItem)).setText("FOOTER");

    listview.addHeaderView(header1);
    listview.addHeaderView(header2);
    listview.addFooterView(footer);

    comicList.setAdapter(adapter);

    return v;
}

}

As much as possible I tried to follow the example on the library. The only thing that I change is I implement it on fragment.And this is my main.xml which causes the InflateException

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

<za.co.immedia.pinnedheaderlistview.PinnedHeaderListView
        android:id="@+id/pinnedListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white">

</za.co.immedia.pinnedheaderlistview.PinnedHeaderListView>

</LinearLayout>

the other layouts works fine.

this is the error:

FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #8: Error inflating class za.co.immedia.pinnedheaderlistview.PinnedHeaderListView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

I dont know where is the problem, I added the library and there is no error on compiling but crashes on runtime. any suggestion guys?

Était-ce utile?

La solution

Clean your project, And right click on your project and go to android tools and click fix project properties. And again run the program.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top