0

I've just recently been asked to work on an Android application. My usual day to day is .NET development so have been using Xamarin to develop this application. Something I'm beginning to regret I think. I've been using 'Xamarin.Android' rather than 'Xamarin.Forms', as the EMDK we are using needs requires that.

I've been trying to display different views on the same activity, trying to make a wizard like form. From different tutorials everything was pointing towards using Fragments, ViewPager and FragmentPagerAdapter.

But I have a lot of obsolete messages.

When I tried out the Fragments based on Microsoft tutorial (which is clearly out of date). I kept getting obsolete warnings and have started using AndroidX.Fragment to get around this. However FragmentPagerAdapter or FragmentStatePagerAdapter gave obsolete warnings as well.

I soon found a solution to that by passing in FragmentPagerAdapter.BehaviorResumeOnlyCurrentFragment in constructor this stopped the deprecated warnings for now.

public ExampleAdapter(FragmentManager fm, List<Fragment> examples) : base(fm,FragmentPagerAdapter.BehaviorResumeOnlyCurrentFragment)

But at this stage I'm feel like I should be using something else to achieve what I'm looking for. I just want an easy wizard form but something that is not going to be out of date in the next year or so.

If fragments are being deprecated then what would the alternative be, and is it something that can be done in Xamarin?

Nick Hunt
  • 3
  • 4

2 Answers2

1

I just want an easy wizard form but something that is not going to be out of date in the next year or so.

From document FragmentPagerAdapter and FragmentStatePagerAdapter,we could find that both FragmentPagerAdapter and FragmentStatePagerAdapter are deprecated.

And we also find that a note:

Switch to androidx.viewpager2.widget.ViewPager2 and use androidx.viewpager2.adapter.FragmentStateAdapter instead.

And if we check document Migrate from ViewPager to ViewPager2,we could find that:

ViewPager2 is an improved version of the ViewPager library that offers enhanced functionality and addresses common difficulties with using ViewPager.

So, try to use ViewPager2 instead.

For more information, you can also check thread :FragmentPagerAdapter deprecated.

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19
0

I have a series of tutorial projects, using the Navigation Component (Single Activity, multiple fragments) Android's recommendation for modern Android development that cover the FragmentStateAdapter, the replacement for what you are using. Fragments have not been deprecated, just replaced with androidx.fragment.app.Fragment.

These projects were initially written as Xamarin.Android but many of them have now been converted to Net7. The same name with Net7 added to the project name. See https://github.com/gmck. My email is there, so you can contact me if you have any queries. Take a look at NavigationGraph7Net7 which has a working example of what you want, but then go back to the beginning to learn about the basics of the Navigation Component.

user2153142
  • 431
  • 1
  • 4
  • 7