I am assuming that function populateListView()
is a function of the Fragment containing the ListView
. You are calling populateListView()
on every call to onPageSelected
. Should you not check what is the position that is being selected. Anyway the populateListView()
method should be a public method of the Fragment containing ListView
. And You Can Instantiate The Fragment from the Viewpager
adapter in the Activity and than call this method. In That way the listView
should not be null.
@Override
public void onPageSelected(int position) {
ListViewFragment frag=(ListViewFragment)adapter.instantiateItem(viewPager, 1);
//here adapter is the ViewPager Adapter and you must supply the viewpager that contains
//the fragments and also the position of the fragment to instantiate.
//For example 0 or 1 etc.
frag.populateListView(getApplicationContext());
aBar.setSelectedNavigationItem(position);
}