orientationchange is never fired
Hello,
I'm trying to implement detection of orientation change in my Android app, to change the layout of elements on the screen.
My application is made by a single window, with some labels and text inputs inside a ScrollView. I implemented this listener:
Ti.Gesture.addEventListener('orientationchange',function(e){
alert('Orientation changed!')
});
But it's never fired.
I can't understand the reason, also because it's working in the kitchensink app, and I don't find antything different in my approach. Can someone help me?
I'm developing on Windows, with Titanium 1.4.
Thank you in advance.
4 Answers
-
Accepted Answer
in fact it looks like Ti.Gesture.addEventListener in app.js doesn't work
you should consider having a separate file for your win1 (which is in my opinion a good pratice)
app.js :
Titanium.UI.setBackgroundColor('#000'); var tabGroup = Titanium.UI.createTabGroup(); var win1 = Titanium.UI.createWindow({ title:'Tab 2', backgroundColor:'#fff', url:'test.js'}); var tab1 = Titanium.UI.createTab({ icon:'KS_nav_views.png', title:'Tab 1', window:win1}); var win2 = Titanium.UI.createWindow({ title:'Tab 2', backgroundColor:'#fff'}); var tab2 = Titanium.UI.createTab({ icon:'KS_nav_ui.png', title:'Tab 2', window:win2}); tabGroup.addTab(tab1); tabGroup.addTab(tab2); tabGroup.open();
test.js
Ti.Gesture.addEventListener('orientationchange',function(e){ alert('Orientation changed!') });
-
i've tried your code (mac) and changing orientation (numpad 7) show the alert.
can you provide your whole code so we can investigate a bit more ?
-
Hi Stephane,
Thank you very much for you answer.
The whole code is a bit long, anyway I tried also adding the listener to the standard "Hello World" app that is generated automatically when a new project is created in Titanium, and it's not working both on emulator (APIs 1.6) and on my Motorola Milestone (Android Froyo preview). Here's the full code:// this sets the background color of the master UIView (when there are no windows/tab groups on it) Titanium.UI.setBackgroundColor('#000'); // create tab group var tabGroup = Titanium.UI.createTabGroup(); // // create base UI tab and root window // var win1 = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor:'#fff' }); var tab1 = Titanium.UI.createTab({ icon:'KS_nav_views.png', title:'Tab 1', window:win1 }); var label1 = Titanium.UI.createLabel({ color:'#999', text:'I am Window 1', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', width:'auto' }); win1.add(label1); // // create controls tab and root window // var win2 = Titanium.UI.createWindow({ title:'Tab 2', backgroundColor:'#fff' }); var tab2 = Titanium.UI.createTab({ icon:'KS_nav_ui.png', title:'Tab 2', window:win2 }); var label2 = Titanium.UI.createLabel({ color:'#999', text:'I am Window 2', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', width:'auto' }); win2.add(label2); // // add tabs // tabGroup.addTab(tab1); tabGroup.addTab(tab2); // open tab group tabGroup.open(); Ti.Gesture.addEventListener('orientationchange',function(e){ alert('Orientation changed!') });
-
Please check this QA and see if it helps.
http://developer.appcelerator.com/question/71051/android-monitor-orientation