I want to make a listener inside my fragment which respond when the fragment become visible. I currently do it with a onPageListener inside the Activity but that doesn't work in my situation. What I need is to execute my AsyncTask in onStart when I enter the fragment. With the onPageListener it tries to do it before.
With a button it works like this :
((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener()
{
@Override
public void onRefresh()
{
// Do work to refresh the list here.
startNewAsyncTask();
}
});
This code comes from a external class which I got from gitHub
A listener which respond to a boolean will already do the thing about not doing it like this : if(true) { code... }
Is that it won't get called when you change to the page you see the viewpager has already started the Fragment so it is inactive when the button is pressed the listener still reacts and that's what I need.