[Java for Android App Development] xDandon:
Hello, I am hoping someone can point out anything I might be doing wrong that is causing my issue. (seems hard to find "best practice" type of advise for newer android features)

My problem is that a ListView which is inside a fragment, controlled by a ViewPager does not get displayed on the screen if I swipe to the next fragment. (but a TextView inside the same fragment shows up fine on all fragment instances),

To set the scene, I have only one fragment class out of which I instantiate all the fragments used by the ViewPager.

Inside the fragments onActivityCreated I create a cursor loader and a custom cursor adapter and on the loaders onLoadFinished I swap the cursor as its supposed to be. Naturally the customCursorAdapter that I created handles the inflation of the listView row in the newView method and binds the data from the cursor in the bindView method.

Does this sound right? I mean I did it this way with the intent of not having tight coupling, having the fragment be independent. So why won't it draw out the listview for subsequent pages? From what I have seen in the logs, all methods get called for all fragments, including getItem, newView, bindView etc.

Final quirk is that the "previous" fragmet's listView does get drawn. Meaning I start on Fragment 1 - listView is there. Move to fragment 2 - listview not there, move to fragment 3 list view not there, move back to fragment 2 list view IS there now, and back to fragment 1 it is NOT there anymore.

I don't have time to post code right now but will as soon as I get a chance.

Thank you all.

//main activity which creates the view pager and adapter and starts the process
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG,"onCreate begin");

super.onCreate(savedInstanceState);
setContentView(R.layout.pager_task_tracking);

viewPager = (ViewPager) findViewById(R.id.pager);

FragmentManager fragmentManager = getSupportFragmentManager();

MyPagerAdapter myPagerAdapter = new MyPagerAdapter(fragmentManager);
viewPager.setOffscreenPageLimit(0); // trying to force drawing of fragments
viewPager.setAdapter(myPagerAdapter);
Log.d(TAG,"onCreate viewPager done");

//MyPagerAdapter getItem (extends FregmentSatePagerAdapter
public Fragment getItem(int i) {
Log.d(TAG,"getItem called with item:"+i);
return TaskListFragment.newInstance(i);
}

//fragment onActivityCreated , this fragment instanciated in getView of viewPager
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

Log.d(TAG, "onActivityCreated with datePointer:"+datePointer);
TextView textViewFragmentTitle = (TextView) getView().findViewById(R.id.fragmentTitle);
textViewFragmentTitle.setText("DATE:"+datePointer);

loaderManager = getLoaderManager();
list = (ListView) getActivity().findViewById(R.id.TaskListView);

customAdapter = new CustomCursorAdapter(getActivity(), null, 1 , datePointer);
list.setAdapter(customAdapter);

loaderID = datePointer; //attempt to get fragment listview to draw - not working

loaderManager.initLoader(loaderID, null, this);
}

///cursor loader onFinish
public void onLoadFinished(android.support.v4.content.Loader<Cursor> loader,
Cursor newCursor) {
Log.d(TAG, "onLoadFinished:"+datePointer);
if (customAdapter != null && newCursor != null ){
Log.d(TAG, "onLoadFinished swapCursor:"+datePointer);
customAdapter.swapCursor(newCursor);
//doesnt help customAdapter.notifyDataSetChanged();
} else {
Log.v(TAG,"OnLoadFinished: mAdapter is null");
}

}

//MyCustomCursorAdapter (used by the listview inside the fragment above)
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View retView = inflater.inflate(R.layout.task_list_item_layout, null);
RelativeLayout.LayoutParams relativeLayoutParameters;
Log.d(TAG,"newView layout inflated:"+datePointer);
return retView;
}

///bindView of same MyCustomCursorAdapter
public void bindView(View view, Context context, Cursor cursor) {
Log.d(TAG,"bindView:"+datePointer);
TextView tvName = (TextView) view.findViewById(R.id.textviewItemName);
tvName.setText(cursor.getString(cursor.getColumnIndex(DBHelper.C_TASK_NAME))+" ["+datePointer+"]");
}

Also check out the LogCat logs with description of the action in the name corresponding to the log statements in the code above.

I noticed more detail about what happens (if you look at the logcat you will see also)

When the screen is displayed the first fragment has the listview present, but the fragment has the id/datePointer (same thing) of "0" BUT the listview items have an id/datePointer of "1"

If you look at the initial logcat you will see "newView layout inflated:1" but no "newView layout inflated:0" how this is being skipped I have no idea. And how the id's can be mix-matched between fragment instances baffles me.

And lastly, after scrolling right twice (to the 0,1, 2nd fragment) it did not have the listview as reported, but scrolling BACK ONE the listview shows up in the 1st fragment ... but even more baffling with lisvtView items that report being part of the "0" fragment .... whaaaat?