I have a main action in which there is a ViewPager. ViewPager uses the FragmentPagerAdapter to place fragments in the ViewPager. All fragments are a PdfAssetFragment that contains a PDFView (Joan Zapata) and a custom view that I wrote under the name DrawingView (which allows the user to draw on the screen). When I make calls to change the properties of the DrawingView that are currently on the page (each individual fragment in the ViewPager has its own PDFView and DrawingView), nothing seems to have changed.
Here is the abstract class that PdfAssetFragment inherits from (this is here, so I can easily extend the class so that I can use different types of media in the ViewPager):
public abstract class AnnotationFragment : Fragment { protected View _view; protected DrawingView _drawingView;
Here is the code for PdfAssetFragment:
public class PdfAssetFragment : AnnotationFragment, IOnPageChangeListener {
AssetPagerAdapter:
/// <summary> /// Handles the displaying of fragments in the asset view pager /// </summary> public class AssetPagerAdapter : FragmentPagerAdapter { private List<IMedia> _assets; private Context _context; /// <summary> /// Instantiates this adapter with a list of assets /// </summary> /// <param name="manager">Manager of this object</param> /// <param name="assets">List of assets to display</param> public AssetPagerAdapter(Context context, FragmentManager manager, List<IMedia> assets) : base(manager) { _context = context; _assets = assets; } /// <summary> /// Gets the number items this adapter manages /// </summary> public override int Count { get { return _assets.Count; } } /// <summary> /// Gets the next fragment to display /// </summary> /// <param name="position">Current index</param> /// <returns>A fragment to display in the view pager</returns> public override Fragment GetItem(int position) { var bundle = new Bundle(); bundle.PutString("ASSET", _assets[position].Url); return PdfAssetFragment.Instantiate(_context, Java.Lang.Class.FromType(typeof(PdfAssetFragment)).Name, bundle); } }
Layout for PdfAssetFragment:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.joanzapata.pdfview.PDFView android:id="@+id/pdf_view" android:layout_width="match_parent" android:layout_height="match_parent"/> <ra16.views.controls.DrawingView android:id="@+id/drawing_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="@dimen/asset_view_margin" android:layout_weight="1"/> </FrameLayout>
This is how I handle view paging: (in MainActivity.OnCreate ())
_pager.PageScrolled += (sender, e) => { if (_currentFragment != null) { AnnotationTypeChanged -= _currentFragment.OnAnnotationTypeChanged; } _currentFragment = SupportFragmentManager.Fragments[e.Position] as AnnotationFragment; AnnotationTypeChanged += _currentFragment.OnAnnotationTypeChanged; };
When I raise the "AnnotationTypeChanged" event, the AnnotationFragments OnAnnotationTypeChanged base class method is launched and it sets the _drawingViews CurrentMode and TouchEventsEnabled properties.
The problem is that after this a touch event occurs in the View drawing, TouchEventsEnabled is always false (by default), which tells me that it just does not change. This seems to be a change inside the AnnotationFragment class, because if I check its property values ββafter setting them in the event handler, they look as expected. It almost seems like I'm no longer working with the same _drawingView ...
To add additional information to all of this: I checked and can confirm that the identifier of each individual _drawingView seems the same.
Any help or suggestions?