Kelvin Rolex
Kelvin Rolex

Reputation: 27

How to get the current item of a viewpager in xamarin Android

Good day guys, Please I am new to xamarin, I have been looking for a way to get the current item of a viewpager, I have searched on google and I saw that Java has ViewPager.getCurrentItem, I have tried this in xamarin Android but did not work.

Please if there is a way to get the current item of a viewpager just show me. Thanks.

Upvotes: 0

Views: 573

Answers (1)

Grace Feng
Grace Feng

Reputation: 16652

The problem now is if I swipe the viewpager it doesn't affect var ID = ViewPager.CurrentItem; it still remain the previous ID when the app was first loaded, please can you tell me exactly where I should put this code (var ID = ViewPager.CurrentItem; ) so that when I swipe the viewpager it gives me the current ID after swiping.

You can get the current item by subscribing the PageSelected event of your ViewPager, for example:

viewPager.PageSelected += (vpsender, ee) =>
{
    Log.WriteLine(LogPriority.Debug, "CurrentItem:", viewPager.CurrentItem.ToString());
};

Upvotes: 1

Related Questions