0

I have a custom FragmentPagerAdapter and a custom ViewPager.

When the Activity is loaded the first two views are loaded as well. These views contain an ImageView with some custom labels drawn on it:

@Override
protected void onDraw(Canvas canvas) {
    Logger.d(iDomsAndroidApp.TAG, "On draw");
    drawLabels();
    super.onDraw(canvas);
}

However, when going to the next page, and the 3rd is loaded, the onDraw of the ImageView is never called, and neither the image, nor the labels are drawn.

(either with swiping or calling specifically:

public void moveNext() {
    mPager.setCurrentItem(mPager.getCurrentItem() + 1);
}

)

Do I need to have a procedure calling the draw when the view appears or something like that?

This is a problem with Android 6.0.1 (API 23), but not with Android 5. Can anybody help me debugging why the draw() is not called when extra pages are loaded after the initial load. I have spend a few hours now, and cannot figure out the difference between Android 5 and 6.

Note: it only happens with the custom ImageView, as all other UI elements like a small WebView seem to be fine.

Edit: The view does redraw if e.g. changing the orientation of the device, so it only seems to be in initial creation, or display.

Edit2: I also tried implementing the FragmentStatePagerAdapter, and call mAdapter.notifyDataSetChanged(); to trigger recreation of the views:

public int getItemPosition(Object item) {
    return POSITION_NONE;
}

This now has the effect that all subsequent views (including the second one) do not have the ImageView populated. So something goes wrong it seems when the Fragment is redrawn,

Luuk D. Jansen
  • 4,402
  • 8
  • 47
  • 90

0 Answers0