Window within view is not clickable
In my app I'm trying to create a window that contains some controls including a view. Within that view I want to have a window containing other controls. The problem is, none of the controls in the window inside the view are functionable. I've tried changing the touchEnabled property of the view between true and false, and neither seems to help.
Here's an stripped-down example of the code that shows the problem I'm encountering:
Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({
backgroundColor: "#c60" // Orange
});
var view1 = Titanium.UI.createView({
top: 0, left: 0, height: 300, width: 300,
touchEnabled: false
});
var win2 = Titanium.UI.createWindow({
backgroundColor: "#c09" // Fuschia
});
win2.addEventListener("open", function(e) {
Titanium.API.info("Window 2 opened");
});
var btn1 = Titanium.UI.createButton({
top: 5, left: 5, height: 60, width: 250,
title: "Test Button"
});
btn1.addEventListener("click", function(e) {
alert("You clicked me!");
});
win2.add(btn1);
view1.add(win2);
win1.add(view1);
win1.open();
A couple things are happening. First of all, the win2 window automatically opens when added to the view even though the .open() method was never called. And secondly, the button inside win2 is not clickable at all.
Like I said, I've tried it with the touchEnabled property toggled either way and it has no effect. Any ideas?
2 Answers
-
Accepted Answer
Hi Levi,
Firstly, I'd like to tell you that it's a rare event to find someone who actually recognises a term like "stripped-down example", let alone one whose code is complete enough to demonstrate the issue without any hacking and emulator restarts. Even though I was ready to close down for the night, I was so surprised, that I started everything up again! :)
And now I have just noticed that you have even tagged it correctly with your target platform! I want to vote your post 1000 times so that everyone sees the fine example that it sets! ;)
I can see that you have the right idea with your code, but the problem is that you cannot add a window to a view. Conversely, you can add a view to a window. I could immediately see a description of the problem when I ran your code because I was running android's adb -e logcat to see logging messages, which showed:
java.lang.IllegalStateException: call to getView on a Window
Obviously that's not an option for you when working with the apple's sdk, but you could use the
TiDev Run Emulator screen and set the filter at the bottom to "Trace".So, replace the last 4 lines of your code with the following and it will work.
view1.add(btn1); win1.add(view1); win1.open();
However, I am mindful that this won't give you your original intended result. Would you have a look at it again, with the information about adding views in mind, and if you need further help, let me know what you are aiming for and I will help you through it.
Good luck, and enjoy it!
-
I just had a similar trouble, so I'd like to to add that adding a window to a window will lead to the same exception :
java.lang.IllegalStateException: call to getView on a Window
So you have to remind that you can nest views but not windows.