2

I'm new to android development and I've been working on android through java(eclipse) till now but now I'm switching to Mono for Android which uses C#.

In java on orientation changed, I've used following code snippet :

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
             Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();

        } else{
             Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
        }
    }

When trying to do the same in C# in Mono for Android, I tried this

 public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
        {
            base.OnConfigurationChanged (newConfig);
            if (newConfig.Orientation == Android.Content.Res.Configuration.ORIENTATION_LANDSCAPE)  
            {
                Toast.MakeText(this, "landscape",ToastLength.Long).Show();
            } 
            else /* if (orientation == 0) */
            {
                Toast.MakeText(this, "portrait", ToastLength.Long).Show();
            }
        }

but Android.Content.Res.Configuration doesn't have any attribute with value 'ORIENTATION_LANDSCAPE` when I try to use following statement

if (newConfig.Orientation == Android.Content.Res.Configuration.ORIENTATION_LANDSCAPE)

What might be the solution? Any other option available?

Any help appreciated !

GAMA
  • 5,958
  • 14
  • 79
  • 126
  • Can you specify "doesn't accept the statement"? Do you get an error message? What is it? – EboMike Feb 15 '12 at 06:58
  • Sorry. I guess I was bit unclear. **I meant `Android.Content.Res.Configuration` doesn't have any attribute with value 'ORIENTATION_LANDSCAPE`**... – GAMA Feb 15 '12 at 07:04

1 Answers1

2

You must use:

Android.Content.Res.Orientation.Landscape

API reference - enum

API refenence - Configuration

Matthew
  • 4,832
  • 2
  • 29
  • 55