Nixit Patel
Nixit Patel

Reputation: 4445

Orientation Changed Event or Listener Android

Is there any event or listener which fires @ time of orientation changed?

or, how to find out that the orientation of phone is changed?

Thank You

Upvotes: 8

Views: 17179

Answers (6)

cyrilchampier
cyrilchampier

Reputation: 2248

Since 180° rotation are not detected by onConfigurationChanged,

See better answer here: How do I detect screen rotation

Upvotes: 0

Norman H
Norman H

Reputation: 2262

If you are more interested in when an orientation change triggers a redisplay of the layout, you might want to check out this: http://developer.android.com/reference/android/view/View.OnLayoutChangeListener.html

"Interface definition for a callback to be invoked when the layout bounds of a view changes due to layout processing."

Upvotes: 1

Janis Rudovskis
Janis Rudovskis

Reputation: 193

On some phones orentation change event fires before actual resize event. Do not recommend u to use orientation change event when u need to know when form is resized.

Just use $(window).resize(function(){ stuff to do })

If u need to have dynamic resize event and change it at some point u can use structure like that

function ResizeEventHandler (){
  var resizeEvent = function(){}

  this.ResizeEvent = function(value){
        if (value!=null) resizeEvent = value;               
        else return resizeEvent()
  }
}

var ResizeEventHandlerInstance = new ResizeEventHandler();

$(window).resize(function(){ ResizeEventHandlerInstance.ResizeEvent();   });

function YourDinamicalEventSetterFunction(){
    ResizeEventHandlerInstance.ResizeEvent(function(){
               alert('resized');
    });
}

basically when u need to change resize event -> change ResizeEventHandlerInstance... and you will not need to unbind event all the time when u want to change it

Upvotes: -1

Akshay Deo
Akshay Deo

Reputation: 528

You can use OrientationEventListener class instead !! http://developer.android.com/reference/android/view/OrientationEventListener.html

Upvotes: 2

kaspermoerch
kaspermoerch

Reputation: 16570

You need to read up on Handling Runtime Changes.

It explains the old way of doing handling stuff like orientation change.

Since Fragments was introduced, they have implemented a new way of doing it (similar to the old one) - but if you don't use Fragments it makes no sense using it.

Upvotes: 4

Phil Kearney
Phil Kearney

Reputation: 157

As far as I know there is a listener for this,

Check out http://developer.android.com/reference/android/view/OrientationListener.html

That is the class have a look through there.

Hope that helped.

Upvotes: 4

Related Questions