I have an app which works in IOS 6. I am trying to get it to work on basically any andriod version.
I have an index controller and view which load fine.
I can load the register page but when I bypass the register page. It works fine in IOS but not Android. I am not using tabgroups just windows.
Any ideas ? NOTE I can't get the full xml tags to load in code view which is why there are no brackets.
I get this error:
new Error("Cannot add window/tabGroup to another window/tabGroup.");
Index Controller
if (!isRegistered) {
var register = Alloy.createController( 'register' );
register.getView().open();
}
else {
var main = Alloy.createController( 'main' );
Alloy.Globals.mainController = main;
}
index view
Alloy
Window id="index"
Require type="view" src="slider" id="slider"
Window
Alloy
main js controller
// code above
$.main.open();
// code below
main view
Alloy
Window id="index"
View id="loadingOverlay" /
View id="main"
ImageView id="background" image="/images/background.jpg"/
Require type="view" src="slider" id="slider" /
/OptionDialog
/View
/Window
/Alloy
Thanks,
the error messag explains it
new Error("Cannot add window/tabGroup to another window/tabGroup.");
hard to tell what is going on here, you might need to add a gist or pastebin, but a window cannot contain another window
Related
I made a Activity using Titanium Mobile Module, and it has simple white background.
Can I pass a window (Titanium object) from this Activity to another js files to add (draw) new objects (like buttons) ?
Yes, you can.
If you are using Alloy for it, just do anything similar as
//index.js
function doClick(e) {
require('utils').createButton($.index);
}
And
//utils.js inside /lib
exports.createButton = function createButton(window){
var button = Ti.UI.createButton({
height:'20dp',
width:'20dp',
title:'Test'
});
window.add(button);
}
However, keep in mind, to your memory consumption, because you are sending a big object $.index as a local variable.
TL;DR I need to change the URL of a WebView I previously created in alloy.js inside a new controller but the URL is not changing no matter what I do. How do I do this?
====================================
I've been having problems left and right with Titanium's webview... Require serious assistance ASAP.
I'm using Alloy. What I'm trying to do is to change the URL of a webview that I've previously created in alloy.js.
My alloy.js file first creates a webview:
Alloy.Globals.webview = Titanium.UI.createWebView();
Alloy.Globals.setUserAgent(); //function that just sets the user agent
Alloy.Globals.webview.url = "http://www.google.ca";
Then on index.js, I have a button where when clicked, it creates and opens a new controller (the controller that contains the webview:
var win = $.index;
...
button.addEventListener('click',function(e)
{
var theTest = Alloy.createController('web').getView();
theTest.open();
win.close();
});
On web.js, I add the WebView (from alloy.js) to a view:
$.view_webview.add(Alloy.Globals.webview);
Still on web.js, I have another view (acts as a button) where when I click on it, it tries to change the url of this the webview I made in alloy.js:
view_getpoints.addEventListener('click', function(e){
$.Alloy.Globals.webview.url = "http://www.youtube.com";
$.Alloy.Globals.webview.reload();
});
This did not work, the url did not change. It was still on google.
I also tried setUrl("http://youtube.com"); instead of just url, nothing.
I then figured it might be because I'm trying to change just the variable, where when I really should be directly changing the element object I added to my $.view_webview view. So I tried that:
view_getpoints.addEventListener('click', function(e){
$.view_webview.getChildren(0).url = "http://www.youtube.com";
}
Aw man, "url" is undefined? Maybe I'm getting the child wrong. Let's output $.view_webview.getChildren(0) and see what we get:
view_getpoints.addEventListener('click', function(e){
Ti.API.info("child: " + $.view_webview.getChildren(0));
}
I was expecting this to output "child: undefined" but no...it isn't undefined..It outputs: "child: [object WebView]".
Whoa whoa whoa, hold on back up. It knows it's a WebView object? But...shouldn't I be able to access the url and setUrl() fields from this object then as stated by the docs?
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.WebView-property-url
Why can't I change it directly?
I'm out of options.
TL;DR I need to change the URL of a WebView I previously created in alloy.js inside a new controller. How do I do this?
I need to get current window in the tabbed application.
I tried with
var win = Ti.UI.currentTab.window();
and with
var win = Ti.UI.currentWindow;
but get the Uncaught TypeError: Cannot call method 'window' of undefined error in both cases.
If you are using TabGroup, you can access current window through activeTab property. It's not global function, so you have to have keep reference to TabGroup object in your code:
var tabGroup = Ti.UI.createTabGroup({ tabs: createTabs() });
tabGroup.activeTab.window
currentTab and currentWindow are holdovers from when you could spin off multiple JavaScript contexts from a Ti.UI.createWindow({ url: 'foo.js' }). I'd recommend you don't use them.
There are a couple of patterns to choose from when you need to communicate from one part of your app to the UI at another part.
1st option: listen for and fire events a la Ti.App.addEventListener('foo', function(data){}) and Ti.App.fireEvent('foo', { }). This decouples the code nicely, so you can move the UI handling code around without changing the firing code.
2nd option: expose the UI objects through modules. In your controller, exports.win = $.win;.
3rd option: set a global object: Alloy.Globals.win = $.win;.
ok so in alloy framework, we just use $ sign to get all the controls which are created in .xml file...
so if you set id of your window tag in .xml file then you can get current window with below example...
.xml file
<Alloy>
<Window id="win">
</Window>
</Alloy>
.js file
var win = $.win
so from above code you can get your current window.
Hope you get it.
Is there any example on refreshing the radio-buttons value, that exist on one page and their value is changed from other page.
I have tried the following but its not working. [ using phonegap+jquerymobile+HTML5 ]
The following is the jquerymobile syntax called by the main page while the radio buttons exist on page2:-
if (result.rows.item(0).pri==0)
{
$('#radio2').prop('checked', true);
}
else {
$('input:radio[id=radio3]').prop('checked', true);
}
$("input[type='radio']").checkboxradio();
$("input[type='radio']").checkboxradio("refresh");
getting the following error on eclipse Android development studio
cannot call refresh before page initialization.
any suggestions??
you may need to regenerate the widgets (the form element) by .triger("create")
Detail please refer Enhancing new markup from http://demos.jquerymobile.com/1.2.0/docs/pages/page-scripting.html
I have a titanium app where I load a web view. In this web view I load a html5 with a chart.
I want to show a vertical line and get some information about the position of the line. This line will be controlled by a slider in Titanium App, so the line would change its position very fast and very often.
You can see something similar here: graph
In html file, I write the graph and I add a listener for an event. When the event is fired, it draw a line in some position with this code:
function updateVerticalLine(posX) {
drawSeries(c);
c.strokeStyle = '#000000';
c.beginPath();
c.moveTo(getXPixel(posX), graph.height() - yPadding);
c.lineTo(getXPixel(posX), 0);
c.stroke();
}
In Titanium app, I only fire the event when I receive the change slider event and I pass the new position of the line:
slider.addEventListener('change', function(e) {
Ti.App.fireEvent('sliderhtml5line:change', {
value : e.value
});
});
It works ok on ios, but on Android, it is very slow and events are disorganized.
Do you know how I can solve it? Is there any better option for this?
Thanks!!
it should be done the otherway.
when the user changes the slider, you should call the method in the HTML page using the evaljs function to update the user interface directly