Reputation: 623
i make simple login and menu display in titanium mobile. here's my code for login:
Login.js
function Login() {
var loginView = Titanium.UI.createView({
backgroundColor:'#C4FBFF',
layout:'vertical'
});
var txtUsername = Titanium.UI.createTextField({
width:'75%',
hintText:'Username',
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
var txtPassword = Titanium.UI.createTextField({
width:'75%',
hintText:'Password',
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
passwordMask:true
});
var btnLogin = Titanium.UI.createButton({
title:'Login',
width:'75%'
});
loginView.add(txtUsername);
loginView.add(txtPassword);
loginView.add(btnLogin);
btnLogin.addEventListener('click',function(e){
var alertDialog = Titanium.UI.createAlertDialog({
title: 'Confirmation',
message: 'You will be logged in as ' + txtUsername.value + ', continue?',
buttonNames: ['Yes','No']
});
alertDialog.addEventListener('click',function(e){
if (e.index === 0){ //Yes Pressed
var isAndroid = Ti.Platform.osname === 'android' ? true : false;
var MainMenu = isAndroid === true ? require('ui/handheld/android/MainMenu') : require('ui/handheld/MainMenu');
var mainMenuWindow = Titanium.UI.createWindow({
backgroundColor:'#336699',
title:'Main Menu',
modal:true,
navBarHidden: isAndroid === true ? true : false
});
var mainMenu = new MainMenu(mainMenuWindow);
mainMenuWindow.add(mainMenu);
mainMenuWindow.open();
}
else{ // No Pressed
makeAlert('Login','Please contact your system administrator');
}
});
alertDialog.show();
});
function makeAlert(title, message) {
var customAlertDialog = Titanium.UI.createAlertDialog({
title: title,
message: message,
buttonNames: ['Ok']
});
return customAlertDialog.show();
}
return loginView;
}
module.exports = Login;
and here's MainMenu.js
function MainMenu(_parent){
var mainMenuView = Titanium.UI.createView({
backgroundColor:'#C4FBFF',
layout:'vertical'
});
var btnLeftNavBar = Titanium.UI.createButton({
title:'Logout'
});
var txtTest = Titanium.UI.createTextField({
hintText:'iPhone',
width:'75%',
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
_parent.setLeftNavButton(btnLeftNavBar);
mainMenuView.add(txtTest);
btnLeftNavBar.addEventListener('click',function(e){
_parent.close();
});
return mainMenuView;
}
module.exports = MainMenu;
MainMenu.js only displayed one button on navBar for close the window..
the main problem is i want to put tabGroup on MainMenu.js so i can choose some menu from it.
is it possible to put tabGroup inside the window? any suggestion, so i can put the tabGroup in MainMenu.js without changing the main application structure?
many thanks..
Upvotes: 1
Views: 3111
Reputation: 1281
It is not possible to add a tabgroup as a children of any other element. Reference: Top Level Containers @ add method of tabgroup
Text:
Top-Level Containers
There are certain top-level containers that are not intended to be added as the children of other views. These top-level containers include Window, SplitWindow, and TabGroup. Other types of views must be added to a top-level container in order to be displayed on screen.
Upvotes: 7