This is my first question in this community that refers to the API of titanium studio. I explain: I'm trying to put a textField inside a listView an item, but when compiled and when to focus on the text area will not let me write and when it does it does in other type of listView.
I hope you can help with this
var win = Ti.UI.createWindow({
backgroundColor:'#FFF'
});
var plainTemplate = {
childTemplates: [
{
type: 'Ti.UI.Label',
bindId: 'title',
properties: {
width: '100%',
height: 30,
left: 0,
top:0
}
},
{
type: 'Ti.UI.TextArea',
bindId: 'campo',
properties: {
top:60,
width: '70%',
left:10,
height:40
}
}
],
events: {click: check }
};
var listView = Ti.UI.createListView({
templates: { 'uncheck': plainTemplate},
defaultItemTemplate: 'uncheck'
});
var data = [];
for (var i = 0; i < 20; i++) {
data.push({
title : { text: 'row' + i },
properties : {
itemId: 'row' + i,
accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_NONE,
}
});
}
var section = Ti.UI.createListSection();
section.setItems(data);
listView.sections = [section];
function check() {
alert('estas aqui!!');
}
win.add(listView);
win.open();
Have you tried out to remove the top-Property in UITextArea of 60px? That could be the reason, why your textarea is at another position as you've expected:
{
type: 'Ti.UI.TextArea',
bindId: 'campo',
properties: {
// top: 60 <--- remove that line
width: '70%',
left:10,
height:40
}
}
I haven't tested your whole code, but i added this value for a top property to a ListView in an App where i am working on and it ended in an similar behaviour as you wrote.
Related
I am new to the scene and wonder how i am to go about this.
I have a switch that should add +1 or a "point" to a label when the switch is true.
and When it is false it should withdraw that same "point".
var win = Ti.UI.createWindow({
backgroundColor: 'white'
});
var view = Ti.UI.createView();
var win = Ti.UI.createWindow({
backgroundColor: 'white'
});
var basicSwitch = Ti.UI.createSwitch({
title: "+1"
});
basicSwitch.addEventListener('click',function(e){
});
var label1=Ti.UI.createLabel({
text: ""
});
view.add(basicSwitch);
win.add(view);
win.open();
My code so far,not much i know.
Here you go first of all their are following errors in your code
1)Making window 2 times
2)Creating a label but not adding to parent container
3)Switch has change event listener instead of click one
4)You can set the switch title
and Here goes the correct code
var win = Ti.UI.createWindow({
backgroundColor : 'white'
});
var view = Ti.UI.createView({
width : Ti.UI.FILL,
height : Ti.UI.FILL
});
var basicSwitch = Ti.UI.createSwitch({
top : 30,
value : false,
});
basicSwitch.addEventListener('change', function(e) {
if (e.value = true) {
label1.text = 1;
} else {
}
});
var label1 = Ti.UI.createLabel({
text : ""
});
view.add(label1);
view.add(basicSwitch);
win.add(view);
win.open();
Thanks
I'm trying to create a label that allows user to select a date in Titanium. My code compiles, but it displays both the date and time when I ask for date only (note: I do my testing with an Android emulator). Can someone take a look at my code and give me a hint on how to solve this issue? Your help is greatly appreciated!
//create a new window
var addWin = Titanium.UI.createWindow({
title: "Add New Entry",
backgroundColor: '#ffffff'
});
//header
//addWin.add(Inova.ui.createHeaderView()); //error
//body
var body = Titanium.UI.createView({
backgroundColor:'#fff',
height: 800,
layout: 'vertical'
});
//Addin a label to the body
body.add(Titanium.UI.createLabel({
text: 'New Travel Entry',
top: 10,
color: '#008000',
textAlign: 'center',
font: {fontSize:20},
width:'auto', //Define width of the label
height:'auto' //Define height of the label
}));
var dateLabel = Titanium.UI.createTextField({
text: 'Date: ',
hintText:'Click here to select a date',
font: {fontSize: 20},
top:20,
left:10,
width:'auto',
height: 'auto',
color: '#336699',
editable:false,
borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED
});
var dateUpdated = false;
dateLabel.addEventListener('click', function(e){
var picker = Titanium.UI.createPicker({
type: Titanium.UI.PICKER_TYPE_DATE,
minDate: new Date(2012,1,1),
maxDate: new Date(2014,12,30),
value: new Date(2013,12,2)
});
picker.showDatePickerDialog({
value: new Date(2012,12,2),
callback: function(e)
{
if (e.cancel)
{
Titanium.API.info('User canceled dialog');
} else
{
Titanium.API.info ('USer selected date: ' + e.value);
dateLabel.value = e.value;
dateLabel.text = (e.value.getMonth() + 1) + '/' + e.value.getDate() + '/' + e.value.getFullYear(),
dateUpdated = true;
}
}
});
});
body.add(dateLabel);
addWin.add(body);
addWin.open();
your problem starts here:
var dateLabel = Titanium.UI.createTextField({
text: 'Date: ',
You are not defining a Label but a TextField. I would change its name to dateField or dateTextField for clarity.
A TextField doesn't have a text property, it has a value property.
You are setting dateLabel.value = e.value; and that's why you are seeing values that the one you mentioned Sun Feb 02 14:08:28 PST 2013. That fragment should change to:
...
var dateUpdated = false;
dateLabel.addEventListener('click', function(e){
...
} else
{
Titanium.API.info ('USer selected date: ' + e.value);
dateLabel.value = e.value.toDateString().slice(4);
dateUpdated = true;
}
...
This way, dateLabel.value will produce something like "Dec 02 2013"
I'm using the code bird library to integrate a twitter feed into a titanium app. At the minute I'm only interested in text and an image. I am getting these elements fine in the console and my entire code is getting no errors, however, the table is not appearing in the app. I have replaced the key and secret key with correct values. See code below:
var tableView= Titanium.UI.createTableView({
zIndex:60
});
var rowData;
var win= Titanium.UI.createWindow({
backgroundColor:"white"
});
var Codebird = require("codebird");
var cb = new Codebird();
cb.setConsumerKey('consumer key', 'consumer secret');
var bearerToken = Ti.App.Properties.getString('TwitterBearerToken', null);
if(bearerToken == null){
cb.__call(
'oauth2_token',
{},
function (reply) {
var bearer_token = reply.access_token;
cb.setBearerToken(bearer_token);
Ti.App.Properties.setString('TwitterBearerToken', bearer_token);
fetchTwitter();
}
);
}
else {
Ti.API.info("We do have a bearer token...----------------------------------------------------------------------------");
cb.setBearerToken(bearerToken);
fetchTwitter();
}
function fetchTwitter(){
var data = [];
cb.__call(
'statuses/user_timeline',
"screen_name=ClassicHits4FM",
function (reply) {
// ...
Ti.API.info("newest and Example that should work just reply------------------------------"+ reply);
Ti.API.info("newest and Example that may work, reply's text ------------------------------"+ reply[0].text);
Ti.API.info("newest and Example that may work, reply's text ------------------------------"+ reply[0].user.profile_image_url);
for(i=0;i<10;i++){
data.push({
title: reply[i].text,
leftImage:reply[0].user.profile_image_url
});
//alert("Data test ----------------------------------"+data[i].title);
}
//Ti.API.info("newest Example that should work, user profile image ------------------------------"+ reply[0].user[0].profile_image_url);
},
true // this parameter required
);
rowData=[];
for(i=0;i<data.length;i++){
var img= Titanium.UI.createImageView({
image:data[i].leftImage,
left:5,
bottom:5,
top:5,
height: '120dp',
width: '120dp'
//height: "120%",
//width: "34%"
});
var title=Titanium.UI.createLabel({
text:data[i].title,
color: 'black',
//left: "38%",
left: '128dp',
right: '4dp',
font:{ fontSize: '15sp', font: 'Droid Serif'}
});
var row=Titanium.UI.createTableViewRow({
height: TI.UI.SIZE
});
row.add(img);
row.add(title);
rowData.push(row);
}
tableView.setData(rowData);
win.add(tableView);
}
win.open();
var tableView= Titanium.UI.createTableView({
zIndex:60,
width : Ti.UI.FILL,
height: Ti.UI.FILL
});
Solved the problem, by moving all code from 'rowdata' onwards into the 'cb.__call' statement block.
Also, in my row definition I had written TI.UI.SIZE which needed to be Ti.UI.SIZE
I want autocomplete textbox like if i press a it should shows related words like apple,aeroplane etc.,i want to make like similar google search.is there any control like this operation in ios and android on titanium.Help with examples codes or it's not possible in titanium?
The following code will work for you. Try it and modify as per your need. Here I Used array(searchArray) as data storage(You can replace it with database field or source whatever as per your requirement).
//Table view showing your autocomplete values
var tblvAutoComplete = Ti.UI.createTableView({
width : '100%',
backgroundColor : '#EFEFEF',
height : 0,
maxRowHeight : 35,
minRowHeight : 35,
allowSelection : true
});
//Starts auto complete
txtAutoComplete.addEventListener('change', function(e){
var pattern = e.source.value;
var tempArray = PatternMatch(searchArray, pattern);
CreateAutoCompleteList(tempArray);
});
//You got the required value and you clicks the word
tblvAutoComplete.addEventListener('click', function(e){
txtAutoComplete.value = e.rowData.result;
});
//Returns the array which contains a match with the pattern
function PatternMatch(arrayToSearch, pattern){
var searchLen = pattern.length;
arrayToSearch.sort();
var tempArray = [];
for(var index = 0, len = arrayToSearch.length; index< len; index++){
if(arrayToSearch[index].substring(0,searchLen).toUpperCase() === pattern.toUpperCase()){
tempArray.push(arrayToSearch[index]);
}
}
return tempArray;
}
//setting the tableview values
function CreateAutoCompleteList(searchResults){
var tableData = [];
for(var index=0, len = searchResults.length; index < len; index++){
var lblSearchResult = Ti.UI.createLabel({
top : 2,
width : '40%',
height : 34,
left : '5%',
font : { fontSize : 14 },
color : '#000000',
text : searchResults[index]
});
//Creating the table view row
var row = Ti.UI.createTableViewRow({
backgroundColor : 'transparent',
focusable : true,
height : 50,
result : searchResults[index]
});
row.add(lblSearchResult);
tableData.push(row);
}
tblvAutoComplete.setData(tableData);
tblvAutoComplete.height = tableData.length * 35;
}
This code worked for me in both ios and android. Hope your problems get resolved:D
cool i can give some example for you with android auto address suggestion bar
var search = Titanium.UI.createTextField({
height : '40sp',
hintText : 'Search',
top : '3sp',
right : '0%',
width : '73%',
textAlign : 'left',
font : {
fontFamily : 'Verdana',
fontSize : '13sp',
},
});
your result dispaly as table row
var resulttable = Ti.UI.createTableView({
top : '0%',
left : '0%',
width : '100%',
height : '100%',
separatorColor : '#000000',
});
and add event listner as change and any change call function with your value and if value is empty remove table from your view
search.addEventListener("change", function(event, type) {
Titanium.API.info("in change event listener");
if ('' != search.value) {
tabgroupContentView.add(resulttable);
if (resulttable.data.length > 0) {
for (var i = resulttable.data[0].rows.length - 1; i >= 0; i--) {
resulttable.deleteRow(i);
}
}
auto_complete(search.value);
} else {
tabgroupContentView.remove(resulttable);
}
});
call following function to auto complte
function auto_complete(search_term) {
loader.open("GET", "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" + search_term + "&types=geocode&language=en&sensor=true&key=bar blar blar this is my key use ur one");
loader.onload = function() {
var histryresult = eval('(' + this.responseText + ')');
jsonArry = histryresult.predictions;
jsonArryterms = histryresult.terms;
for (var i = 0; i < jsonArry.length; i++) {
var service_row = Ti.UI.createTableViewRow({
height : '70sp',
width : '100%',
backgroundColor : '#ffffff',
backgroundFocusedColor : '#FF8F2F',
backgroundSelectedColor : '#FF8F2F',
hasChild : false
});
var lbl_oderid = Ti.UI.createLabel({
left : '3%',
top : '10%',
text : jsonArry[i].terms[1].value,
color : '#A70CAF',
font : {
fontSize : '17sp',
fontWeight : 'bold'
},
height : 'auto',
width : 'auto'
});
var descriptiontext;
if (jsonArry[i].description == undefined) {
descriptiontext = 'Not Valable';
} else {
descriptiontext = jsonArry[i].description;
}
var lbl_description = Ti.UI.createLabel({
left : '5%',
top : '50%',
text : descriptiontext,
color : '#000000',
font : {
fontSize : '12sp',
},
height : 'auto',
width : 'auto'
});
service_row.add(lbl_oderid);
service_row.add(lbl_description);
service_row.addEventListener('click', function(e) {
var locaName = jsonArry[e.index].description;
if (jsonArry[e.index].description == undefined) {
} else {
reversGeoloader.open("GET", "http://maps.googleapis.com/maps/api/geocode/json?address=" + locaName + "&sensor=false");
reversGeoloader.onload = function() {
var geoResult = eval('(' + this.responseText + ')');
jsonArry = geoResult.results;
var newlat = jsonArry[0].geometry.location.lat;
var newlng = jsonArry[0].geometry.location.lng;
curentlatitude = newlat;
curentlongitude = newlng;
getReversGeo(curentlatitude, curentlongitude, 'str');
usercurentlocation.setText('Set by serch');
tabTestWindow.close();
};
reversGeoloader.send();
}
});
resulttable.appendRow(service_row);
}
};
loader.send();
}
textField.addEventListener('change', function(e) {
// you can fill a tableView in this event with the suggested data
});
or this tutorial link might solve your problem
AutoCompleteTextField
I have a view in Sencha Touch which I populate via the initialize function. Here's the code:
Ext.define("Pycsell.view.Home", {
extend: "Ext.form.Panel",
requires: "Ext.form.FieldSet",
alias: "widget.homepage",
config:{
scrollable: false,
cls: 'splash_screen',
layout: 'vbox'
},
initialize: function () {
this.callParent(arguments);
var fb_login = {
xtype: 'button',
cls: 'fb_login_button'
};
var tradreg = {
xtype: 'button',
cls: 'tradreg_button'
};
var tradlog = {
xtype: 'button',
cls: 'tradlog_button'
};
var logo_container = Ext.create('Ext.Panel', {
cls: 'logo_container',
width: '90%',
flex: 4,
});
var button_container = Ext.create('Ext.Panel', {
cls: 'splash_content',
items: [fb_login, tradreg, tradlog],
flex: 2,
});
this.add([
logo_container,
button_container
]);
this.setButtonSizes();
},//End init
setButtonSizes: function() {
console.log('Width is:' + $('.fb_login_button').width());
console.log('Old height is:' + $('.fb_login_button').height());
var height = $('.fb_login_button').width()*0.29;
$('.fb_login_button').height(height);
console.log('New height is:' + $('.fb_login_button').height());
}
});
Now, the setButtonSizes function does fire, but all the values are null, leading me to believe that the items haven't actually been initialized at the time it's called. How would I go about doing this properly so that the values are actually set? Thanks in advance.
This can be notoriously tricky to get right. The problem is that your function is probably being called before the component is rendered. I haven't done any work with Sencha Touch 2, but it looks like using the painted event should help. Something like this:
Ext.define("Pycsell.view.Home", {
extend: "Ext.form.Panel",
requires: "Ext.form.FieldSet",
alias: "widget.homepage",
config:{
scrollable: false,
cls: 'splash_screen',
layout: 'vbox'
},
initialize: function () {
this.callParent(arguments);
var fb_login = {
xtype: 'button',
cls: 'fb_login_button'
};
var tradreg = {
xtype: 'button',
cls: 'tradreg_button'
};
var tradlog = {
xtype: 'button',
cls: 'tradlog_button'
};
var logo_container = Ext.create('Ext.Panel', {
cls: 'logo_container',
width: '90%',
flex: 4,
});
var button_container = Ext.create('Ext.Panel', {
cls: 'splash_content',
items: [fb_login, tradreg, tradlog],
flex: 2,
});
this.add([
logo_container,
button_container
]);
/* Attaches a listener to the component that will be fired after the
component is rendered or shown. */
this.on('painted', this.setButtonSizes);
},//End init
setButtonSizes: function() {
console.log('Width is:' + $('.fb_login_button').width());
console.log('Old height is:' + $('.fb_login_button').height());
var height = $('.fb_login_button').width()*0.29;
$('.fb_login_button').height(height);
console.log('New height is:' + $('.fb_login_button').height());
}
});
Depending on quite what you're trying to accomplish, this may fire the event too many times (looks like it fires every time the component is shown too). So you may have to adjust setButtonSizes to compensate.