bungleofsketches
bungleofsketches

Reputation: 554

Why does onScrollListener think ListView is not created?

So the error that is thrown is

java.lang.IllegalStateException: Content view not yet created

This is thrown when I uncomment the getListView().setOnScrollListener(this); line.

public class MyCategoryFragment extends ListFragment implements OnScrollListener {
    private ArrayList<Article> m_articles = new ArrayList<Article>();
    public ArticleAdapter m_artadapter;


    public MyCategoryFragment() {
        super();
    }

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

        m_articles = manager.loadCategory(getActionBar().getTitle().toString(), 10);
        m_artadapter = new ArticleAdapter(this.getActivity(), R.layout.article_button, m_articles);
        this.setListAdapter(m_artadapter);

        //getListView().setOnScrollListener(this);
        return rootView;
    }

Here is the layout just so you can see it is the correct listview

<?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"
        >
    <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />
    <TextView
            android:id="@android:id/empty"
            android:textColor="#FFFFFF"
            android:textSize="30sp"
            android:gravity="center_vertical|center_horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="It's not you it's us..."/>
</LinearLayout>

I have researched this extensively and I believe in must be something so simple but it is taking more than a day to fix this. Thanks

Upvotes: 0

Views: 117

Answers (1)

Broak
Broak

Reputation: 4187

as the onCreateView doc stays:

creates and returns the view hierarchy associated with the fragment so since the method does not return, you will are not able to access the ListView through getListView(). You can obtain a valid reference in the OnActivityCreate callback.

Upvotes: 2

Related Questions