Search code examples
androidxamarinposition

How to get Gallery focus position


I'm playing with Xamarin Gallery. Wish to get the focus position from time to time.

When reach 1 seconds it will go to OnTimedEvent, here the code

 System.Timers.Timer timer = new System.Timers.Timer();
 timer.Interval = 1000;
 timer.Elapsed += OnTimedEvent;
 timer.Enabled = true;

On the OnTimedEvent i would like to get the focus position;

 private void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
 {
     int position = gallery.SelectedItemPosition();
 }

Hope someone can help, Thanks


Solution

  • I get it already. I forget that we can use ToString() to get the data.

    Here the code :

    int position;
    int.TryParse(gallery.SelectedItemPosition.ToString(), out position);
    

    Sorry that i'm new in Xamarin Android. Thanks for view.