We have an Android.Support.V4.App.Fragment class called 'AbstractFestivalActsFragment' with an OnCreateView() function. The app crashes when calling this function at the following line: this.AssignResourceProperties (view); with error:
Resource with ID 'nowPlayingButton' is of a non-native type and cannot be automatically resolved
At the top of the class an ImageButton is created in this way:
[AndroidResource ("nowPlayingButton")] public ImageButton NowPlayingButton { get; private set; }
This AndroidResource is an Attribute class named AndroidResourceAttribute:
public class AndroidResourceAttribute : Attribute { public AndroidResourceAttribute(string resourceId, bool checkForNull = true); public bool CheckForNull { get; } public string ResourceId { get; } public virtual int GetResource(Context context); }
The whole OnCreateView function:
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { bool b = (ViewModel.GetTotalModelCount() == 0); if (b) { var view = new NoTimetableResultsViewHolder (inflater.Inflate (Resource.Layout.NoTimetableResultsView, container, false)); if (this is FestivalProgramFragment) { view.TextLabel.Text = view.TextLabel.Text.Replace("timetable", "program"); } view.ItemView.SetBackgroundColor(Android.Graphics.Color.White); ((LinearLayout) view.ItemView).SetGravity(GravityFlags.Center); return view.ItemView; } else { var view = inflater.Inflate ((this is FestivalProgramFragment ? Resource.Layout.FestivalProgramFragment : Resource.Layout.FestivalTimetableFragment), container, false); //Exception making it crash this.AssignResourceProperties (view); if (ViewModel.HasNowPlaying) { NowPlayingButton.Click += HandleNowPlayingButtonClick; } else { NowPlayingButton.Visibility = ViewStates.Invisible; } FavoritesButton.Click += HandleFavoritesButtonClick; SelectDayButton.Click += ShowFilterDatePicker; if (ViewModel.DateFilter.HasValue) { SelectDayButton.Selected = true; SelectDayButton.Text = ViewModel.DateFilter.Value.ToString ("m"); } else if (ViewModel.NowPlaying) { NowPlayingButton.Selected = true; SelectDayButton.Text = "Select a day"; } else { SelectDayButton.Selected = true; SelectDayButton.Text = "All days"; } // BUG: The ViewPager object seems to be partially shared unless the id is unique. // This only seems to occur for the ViewPager and even when the adapter is different. ViewPager = view.FindViewById<ViewPager> ((this is FestivalProgramFragment) ? Resource.Id.stageViewpager1 : Resource.Id.stageViewpager2); ViewPager.Adapter = GetViewPagerAdapter(); TabStrip = view.FindViewById<TabLayout> (Resource.Id.tabStrip); TabStrip.SetTabTextColors(Android.Graphics.Color.White, Android.Graphics.Color.White); ResetTabStrip(); return view; } }
I solved the problem by changing the way to find ImageButtons in the layout file.
Previously:
[AndroidResource ("nowPlayingButton")] public ImageButton NowPlayingButton { get; private set; }
Now in OnCreateView():
NowPlayingButton = view.FindViewById<ImageButton>(Resource.Id.nowPlayingButton);
Answers
I solved the problem by changing the way to find ImageButtons in the layout file.
Previously:
Now in OnCreateView():