Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to get selected current tab of a TabHost control after changing the orientation of the android

I am working with Tabhost control in Android C#. It has 4 items. when I am selecting the 2nd tab item (in portrait mode) it shows the correct item of 2nd tab properly (in portrait mode), but when I am changing the rotation from Portrait to landscape then by default OnCreate() method is firing and then Tabhost current tab is set to -1 and every time it selects the 1st tab automatically in landscape mode.

How to resolve this problem. It is happening every time I change the orientation.

Best Answer


  • soumenhaldersoumenhalder Member ✭✭✭

    @jezh said:

    Could you try to add the following code:

    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation ,

    it will not call the Oncreate() and remember the selected position last time when you change the orientation.

     [Activity (ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
      public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity{

    Thank you So much @jezh
    this is working as perfect as I want.

Sign In or Register to comment.