0

In the view:

I have a view like that:

<Alloy>
<TabGroup id="tab1">
    <Tab id="findtab">
        <Window id="window1"></Window>
    </Tab>
    <Tab id="tab2">
        <Window id='window2'></Window>
    </Tab>
 </TabGroup>
</Alloy>

In the controller:

How to set the title for window1?

daniula
  • 6,898
  • 4
  • 32
  • 49
knowwebapp.com
  • 95
  • 4
  • 16

3 Answers3

1

Use:

$.window1.title="my title"
Julian Buss
  • 1,114
  • 7
  • 14
  • Because I have 2 windows in 2 tab of a tabgroup. I have tested for 2 answers above but they are don't work for me. – knowwebapp.com Oct 17 '13 at 18:56
  • I have the same kind of view in one of my apps, and $..title = "some title" works fine. What exactly happens in your case? Do you see the window titlebar? What happens if you use in your XML? – Julian Buss Oct 18 '13 at 05:32
  • I tested on android emulator, It is blank when I set from controller but I set from the view, It show truly as specific title. – knowwebapp.com Oct 18 '13 at 10:21
  • ok, I tested on iOS, sorry, I cannot say if it's different on android. If you have the chance, test on iOS, too and see if it works there. – Julian Buss Oct 18 '13 at 10:57
  • Thanks for your enthusiasm help :) – knowwebapp.com Oct 18 '13 at 13:08
1

I believe your issue is that the window is not fully created by the time your are trying to set the title.

I act upon the focus event of the tabgroup (which actually bubbles up from the tab) and I assign the ActionBar title based on the tab.

For ActionBars within TabGroups, I do the the following:

View:

<Alloy>
  <TabGroup id="tabGroup1">
    <Tab id="tab1">
      <Window id="window1"></Window>
    </Tab>
    <Tab id="tab2">
      <Window id='window2'></Window>
    </Tab>
  </TabGroup>
</Alloy>

Controller:

/**
 * Listen to focus on the tabgroup and pass the title to the ActionBar
 */
$.tabGroup1.addEventListener('focus', function(){

 if( OS_ANDROID && Ti.Platform.Android.API_LEVEL >= 11 ) {

    var tabGroup = $.tabGroup1,
        activity = tabGroup.getActivity(),
        actionBar;

    if(!activity){
        Ti.API.error('No activity created for mainTabGroup');
    } else {
        actionBar = activity.actionBar;

        if(!actionBar){
            Ti.API.error('No ActionBar created for mainTabGroup activity');
        } else {
            actionBar.setTitle(tabGroup.activeTab.title);
        }
    }

 }
});

$.mainTabGroup.open();

By using the focus event of the TabGroup your are ensuring the components are available when you need to modify them.

lsdriscoll
  • 41
  • 3
0

Here you go

$.window1.title='MY custom title';

Thanks

Wahhab_mirza
  • 1,484
  • 2
  • 10
  • 17
  • Thanks your answer, but It don't work for me. I have debug on android simulator. The compiler pass that code row, but the window title don't set. I also try with $.window1.setTitle("Title here"); but It's not still set. – knowwebapp.com Oct 17 '13 at 18:58