I would like to enter a text into a textfield and when i press a button on the same window a new window opens with a tableview and another button. When pressed to the tableview, you can see the value entered to the textfield. When pressed to the button you will return to the first window where you enter a text to enter a new text. So it's like a cycle. My problem is, when i click to the second button and enter another text, and go to the tableview to see the texts i see the second text at both tableviewrows. I appreciate your help.
5 Answers
var totalperson = 0;
var window = Ti.UI.createWindow({
backgroundColor:'white'
});
var text = Titanium.UI.createTextField({
top:10,
left:100,
width:300,
hintText:'Enter name',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
window.add(classes);
var Button = Titanium.UI.createButton({
title:'OK',
top:250,
left:175,
width:140,
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
});
window.add(Button);
Button.addEventListener('click',function(e){
totalperson++;
var newwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
data=[];
data[0]= Ti.UI.createTableViewRow({title:'view names',hasChild:true});
var newtable = Ti.UI.createTableView({
data:data
});
newwindow.add(newtable);
var newbutton = Titanium.UI.createButton({
title:('add new class')
});
newwindow.add(newbutton);
newbutton.addEventListener('click', function(e){
newwindow.close();
text.value='';
});
newtable.addEventListener('click',function(e){
var people = [];
people[0] = Ti.UI.createTableViewRow({title:'people',hasChild:true});
var newerwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
var newertable = Ti.UI.createTableView({
data:people
}); newerwindow.add(newertable);
people[0].addEventListener('click',function(e){
var newestwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
y=[];
for(var i=0;i<totalperson;i++){
y[i]=Ti.UI.createTableViewRow({title:classes.value + ' ' + time.value});
}
var bigtable = Ti.UI.createTableView({
data:y
});
newestwindow.add(bigtable);
}
});
It is something like this. Don't worry about the navigation. When I run the true version when I press "newbutton" and type a new text and want to view it it shows the second text at the last tableview
Hi Solen
Cheers for this - quick tip though add three ~ above the first line of code and three more ~ below the last line. It styles the code and makes it easier to work out. I have cleaned you code and put it at as a comment on your question - top help others.
Before we start can you confirm the first block of code for me as it appears to start of with an error straight away.
You add a textfield called text, but you yo never add it to the window - instead you add something called classes
var text = Titanium.UI.createTextField({ top: 10, left: 100, width: 300, hintText: 'Enter name', keyboardType: Titanium.UI.KEYBOARD_DEFAULT, returnKeyType: Titanium.UI.RETURNKEY_DEFAULT, borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED }); window.add(classes); // so why add something called classesFurther into your code you reference both
text and classes.
Can you review this and amend as required. I suspect the problem may relate to this issue, and if not it would be good to have the code fixed before we review it.
// Flags, is this for Android or iPhone? var iPhone = false; var Android = false; if(Ti.Platform.osname == 'iphone'){ iPhone = true }; if(Ti.Platform.osname == 'android'){ Android = true };
// our navigation function, to be compatible with both platforms function NavigationController(a){ // this is to avoid errors a = a || {}; a.window = a.window || Ti.UI.createWindow(); // this is to handle the iPhone Nav functionality if(iPhone){ var win = Ti.UI.createWindow(); var nav = Ti.UI.iPhone.createNavigationGroup({ window: a.window }); win.add(nav); win.push = function(e){ nav.open(e); }; return win; } // there is no Nav in Android, so let's return the window if(Android){ a.window.push = function(e){ e.open({ fullscreen:false }); } return a.window; } }
var mondaycourse = 0; var tuesdaycourse = 0; var wednesdaycourse = 0; var thursdaycourse = 0; var fridaycourse = 0; var classnumber = mondaycourse + tuesdaycourse + wednesdaycourse + thursdaycourse + fridaycourse; // start the app right here var win = Ti.UI.createWindow({ backgroundColor:'white' }); var data = [];
data[0] = Ti.UI.createTableViewRow({hasChild:true,title:'Schedules'});
var table = Ti.UI.createTableView({
data:data
});
win.add(table);
// let's call our custom navigation function var navigation = NavigationController({ window:win }); // open it navigation.open(); data[0].addEventListener('click',function(){
var win2 = Ti.UI.createWindow({
backgroundColor:'white'
});
var data2=[];
data2[0] = Ti.UI.createTableViewRow({hasChild:true,title:'New Schedules'});
var table2 = Ti.UI.createTableView({
data:data2
});
win2.add(table2);
navigation.push(win2);
data2[0].addEventListener('click',function(){
var win3 = Ti.UI.createWindow({
backgroundColor:'white'
});
var classes = Titanium.UI.createTextField({
color:'#336699',
top:10,
left:100,
width:300,
hintText:'Enter class name',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win3.add(classes);
var days = Titanium.UI.createTextField({
color:'#336699',
top:80,
left:100,
width:300,
hintText:'Enter day',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win3.add(days);
var time = Titanium.UI.createTextField({
color:'#336699',
top:150,
left:100,
width:300,
hintText:'Enter time period',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win3.add(time);
var Button = Titanium.UI.createButton({
title:'OK',
top:250,
left:175,
width:140,
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
});
win3.add(Button);
navigation.push(win3);
Button.addEventListener('click',function(e){ if(classes.value != '' && days.value != '' && time.value != ''){ classnumber++; var newwindow = Ti.UI.createWindow({ backgroundColor:'white' }); include=[]; include[0]= Ti.UI.createTableViewRow({title:'view current schedule',hasChild:true}); var newtable = Ti.UI.createTableView({ data:include }); newwindow.add(newtable); var newbutton = Titanium.UI.createButton({ title:('add new class') }); newwindow.add(newbutton);
navigation.push(newwindow);
var monday = 'monday';
var tuesday = 'tuesday';
var wednesday = 'wednesday';
var thursday = 'thursday';
var friday = 'friday';
if(days.value == monday){
mondaycourse++;
}
else if(days.value == tuesday){
tuesdaycourse++;
}
else if(days.value == wednesday){
wednesdaycourse++;
}
else if(days.value == thursday){
thursdaycourse++;
}
else if(days.value == friday){
fridaycourse++;
}
y=[];
for(var x=0; x<classnumber;x++){
y[x]=Ti.UI.createTableViewRow({title:classes.value + ' ' + time.value});
}
newbutton.addEventListener('click', function(e){
newwindow.close();
});
newtable.addEventListener('click',function(e){
var dayofweek = [];
dayofweek[0] = Ti.UI.createTableViewRow({title:'Monday',hasChild:true});
dayofweek[1] = Ti.UI.createTableViewRow({title:'Tuesday',hasChild:true});
dayofweek[2] = Ti.UI.createTableViewRow({title:'Wednesday',hasChild:true});
dayofweek[3] = Ti.UI.createTableViewRow({title:'Thursday',hasChild:true});
dayofweek[4] = Ti.UI.createTableViewRow({title:'Friday',hasChild:true});
var newerwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
var newertable = Ti.UI.createTableView({
data:dayofweek
}); newerwindow.add(newertable); navigation.push(newerwindow);
dayofweek[0].addEventListener('click',function(e){
var newestwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
if(days.value == monday){
for(var n=0;n<mondaycourse;n++){
y[n]=Ti.UI.createTableViewRow({title:classes.value + ' ' + time.value});
}
var bigtable = Ti.UI.createTableView({
data:y
});
newestwindow.add(bigtable);
}
navigation.push(newestwindow);
});
dayofweek[1].addEventListener('click',function(e){
var b=[];
for(var j=0;j<tuesdaycourse;j++){
b[j] = Ti.UI.createTableViewRow({title: classes.value + ' ' + time.value});
}
var newestttable = Ti.UI.createTableView({
data:b
});
var newesttwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
newesttwindow.add(newestttable);
navigation.push(newesttwindow);
});
dayofweek[2].addEventListener('click',function(e){
var c=[];
for(var k=0; k<wednesdaycourse; k++){
c[k] = Ti.UI.createTableViewRow({title: classes.value + ' ' + time.value});
}
var newesttttable = Ti.UI.createTableView({
data:c
});
var newestttwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
newestttwindow.add(newesttttable);
navigation.push(newestttwindow);
}); dayofweek[3].addEventListener('click',function(e){
var d=[];
for(var l=0;l<thursdaycourse;l++){
d[l] = Ti.UI.createTableViewRow({title: classes.value + ' ' + time.value});
}
var newestttttable = Ti.UI.createTableView({
data:d
});
var newesttttwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
newesttttwindow.add(newestttttable);
navigation.push(newesttttwindow);
}); dayofweek[4].addEventListener('click',function(e){
var e=[];
for (var m=0;m<fridaycourse;m++){
e[m] = Ti.UI.createTableViewRow({title: classes.value + ' ' + time.value});
}
var newesttttttable = Ti.UI.createTableView({
data:e
});
var newesttttttwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
newesttttttwindow.add(newesttttttable);
navigation.push(newesttttttwindow);
});
}); }//if için
else{
alert('Fill the missing data!!!');
}
});
}); });
dayofweek[0].addEventListener('click',function(e){ var newestwindow = Ti.UI.createWindow({ backgroundColor:'white' }); if(days.value == monday){ for(var n=0;n<mondaycourse;n++){ y[n]=Ti.UI.createTableViewRow({title:classes.value + ' ' + time.value}); } var bigtable = Ti.UI.createTableView({ data:y }); newestwindow.add(bigtable); } navigation.push(newestwindow); }); dayofweek[1].addEventListener('click',function(e){ var b=[]; for(var j=0;j<tuesdaycourse;j++){ b[j] = Ti.UI.createTableViewRow({title: classes.value + ' ' + time.value}); } var newestttable = Ti.UI.createTableView({ data:b }); var newesttwindow = Ti.UI.createWindow({ backgroundColor:'white' }); newesttwindow.add(newestttable); navigation.push(newesttwindow); }); dayofweek[2].addEventListener('click',function(e){ var c=[]; for(var k=0; k<wednesdaycourse; k++){ c[k] = Ti.UI.createTableViewRow({title: classes.value + ' ' + time.value}); } var newesttttable = Ti.UI.createTableView({ data:c }); var newestttwindow = Ti.UI.createWindow({ backgroundColor:'white' }); newestttwindow.add(newesttttable); navigation.push(newestttwindow); }); dayofweek[3].addEventListener('click',function(e){ var d=[]; for(var l=0;l<thursdaycourse;l++){ d[l] = Ti.UI.createTableViewRow({title: classes.value + ' ' + time.value}); } var newestttttable = Ti.UI.createTableView({ data:d }); var newesttttwindow = Ti.UI.createWindow({ backgroundColor:'white' }); newesttttwindow.add(newestttttable); navigation.push(newesttttwindow); }); dayofweek[4].addEventListener('click',function(e){ var e=[]; for (var m=0;m<fridaycourse;m++){ e[m] = Ti.UI.createTableViewRow({title: classes.value + ' ' + time.value}); } var newesttttttable = Ti.UI.createTableView({ data:e }); var newesttttttwindow = Ti.UI.createWindow({ backgroundColor:'white' }); newesttttttwindow.add(newesttttttable); navigation.push(newesttttttwindow); }); }); }//if için else{ alert('Fill the missing data!!!'); } }); }); });
Hi Solen
Reading your code I am getting stuck with your nav controller. Can you tell me what you are doing with the push lines as far as I can see these are not valid commands from the createWindow event and not the correct syntax for javascript either.
function NavigationController(a) { // this is to avoid errors a = a || {}; a.window = a.window || Ti.UI.createWindow(); // this is to handle the iPhone Nav functionality if (iPhone) { var win = Ti.UI.createWindow(); var nav = Ti.UI.iPhone.createNavigationGroup({ window: a.window }); win.add(nav); win.push = function (e) { // problem starts here for iOS nav.open(e); }; return win; } // there is no Nav in Android, so let's return the window if (Android) { a.window.push = function (e) { // problem starts here for iOS e.open({ fullscreen: false }); } return a.window; } }Push would normally follow this syntax, when applied to an array;
arrayExample.push(newArrayElement);Let me know.
Also - does ANY of this code actually work as I cannot get the app to even run using the code supplied.
Your Answer
Think you can help? Login to answer this question!