4

I am making android mobile app on titanium Alloy 1.2.2

I want to access elements contained in external views. So if I use

var win=Alloy.createController().getView();

it itself opens that view. I dont need that. I just want to access an element in that view and change its visibility to false. How can we do that? Thanx in advance.

Abhinav
  • 722
  • 2
  • 11
  • 27
  • You can access the child elements of your view, for example if you have your main view and you want to access a label inside another controller which has another view you'll have to do something similar to this: `mainView.children[0].children[0].children[0]` – Mario Galván Oct 22 '13 at 19:28

3 Answers3

1

use Alloy.createController('name').__views to get views outside the controller, e.g.:

// fruit.xml
<Alloy>
    <View id='opacity_view'></View>
</Alloy>

// other.js: 
the_view = Alloy.createController('fruit').__views.opacity_view
Siwei
  • 19,858
  • 7
  • 75
  • 95
0

Another solution is to export the property but you'll need the reference of your controller which you already have it.

var win=Alloy.createController('Path to your controller');

In the .js of the controller you need:

exports.element = $.elementid;

Then you can access win.element.visible = false or whatever property you need.

Mario Galván
  • 3,964
  • 6
  • 29
  • 39
0

controller.getView() doesn't show view on the screen. Probably in controller which you initialize you have code similar to this: $.index.open() which adds new view on device screen.

If you want to hide element when view is created the best way is to create .tss file where you put rule: visible: false using either #id or .class.

Check more in Alloy Styles and Themes documentation.

daniula
  • 6,898
  • 4
  • 32
  • 49