Tab refresh - window to previous state
This is probably a big newbie question, but I'm stuck…
I have a tab (tab 1) that shows window A. Inside window A something happens and then window A is changed into window B.
Now what I need is when I go to tab 2, and then back to tab 1 that window A is shown again. And not window B.
I believe it has to do with the focus, but I can't find out how to achieve this.
Could someone help me please?
8 Answers
-
Simple example where you enter text in the first tab and when you come back to the tab, the value is reset.
You can test that it only resets after you have gone to another tab by modifying the text in the first tab, then closing and reopening the application. When you reopen, the original text should remain since you have not closed the application… you only put it in the background.
// 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 textField1 = Titanium.UI.createTextField({ color:'#999', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', top:10, left:10, height:35, width:250, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED }); win1.add(textField1); // // 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(); // // when the tabGroup gets focus, check to see if the first // tab is the one getting the focus, if so reset it's value if // it was not the last tab to have the focus tabGroup.addEventListener('focus', function(e){ if (e.index == 0 && e.previousIndex != 0) { // reset to original state textField1.value = ''; } });
-
still no answer for this ? i got the same problem
-
just checking back to see if you ever got this working
-
I think the fact that switching Tabs does not close previous subwindows is a missing feature. All Native Apps on the iphone i checked, do this.
-
you should be use "window focus event".
Titanium.UI.currentWindow.addEventListener('focus',winopened); function winopened(e) { alert("win opened"); }
-
I have the same question, but specifically:
I have a "home" tab and other tabs. "home" is the default (first) tab opened. The user can then click through several windows from this one, all opened with Titanium.UI.currentTab.open.
If the user clicks another tab, and then clicks the "home" tab again, I need the initial "home" window to display.
How do I achieve this so that it works on both iPhone and android?
-
Try doing this. Just open the window you want it to open along with the change you want to make in that window on the tabView's (focus) event listener.
tabGroup.addEventListener('focus', function(e){ if (e.index == 0 && e.previousIndex != 0) { // reset to original state with the first window on your tab win1.open(); textField1.value = ''; } });
-
Hi Jeroen,
You MIGHT theoretically be able to do that if you put "Ti.UI.currentWindow.close();" in a blur event listener in Window B.
Titanium.UI.currentWindow.addEventListener('blur', function(e){ Ti.UI.currentWindow.close(); });
However that would only work if you didn't open any windows FROM window B!
Or maybe do the same in the tabgroup click listener:
Titanium.UI.currentTabGroup.addEventListener('click', function(e){ Ti.UI.currentWindow.close(); });
…just a couple of options to play with.
cheers,
Chris.