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

soumenhaldersoumenhalder ✭✭Member ✭✭

Hi,
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

Answers

  • soumenhaldersoumenhalder ✭✭ Member ✭✭

    @jezh said:
    @soumenhalder

    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.