Skip to content Skip to sidebar Skip to footer

Implements OnScrollListener Inside ListFragment

I implemented OnScrollListener interface in ListFragment, and i want to change text when last element of list is visible but it doesn't work. I didn't find example of similar probl

Solution 1:

You have implemented the OnScrollListener, but you havent attached it to your ListView.

getListView().setOnScrollListener(this);

add this to your onCreateView Method.


Solution 2:

You have this error because you are trying to access your Listview when this one is not created yet.

Caused by: java.lang.IllegalStateException: Content view not yet created

Your Listview is actually created by the last line of your onCreateView method, at the line which usually look something like this:

return inflater.inflate(R.layout.fragment_list, container, false);

The solution is to access your list from the onActivityCreated method, which is executed just after the onCreateView method.

    @Override
    public void onActivityCreated (Bundle savedInstanceState){
        // Always call the superclass so it can save the view hierarchy state
        super.onCreate(savedInstanceState);

        getListView().setOnScrollListener(this);
    }

Post a Comment for "Implements OnScrollListener Inside ListFragment"