tableview not being displayed - android

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

Related

Titanium : Ti.UI.SIZE doesn't work properly on Android

I generate a tableView in a loop, and i put a label in each row, which has different length of text each time. I set the rows' height like this:
height : Ti.UI.SIZE,
and it works pretty good, the rows' heights are always big enough to display the full text. But when i swipe up and down, the rows' heights changes for no reason: they become very big or very small, and i have no idea why. I'll paste in the code snippet that causes the problem. It only works bad on Android, it works perfectly on mobileweb.
var i = 0;
var tableList = Ti.UI.createTableView({
separatorColor : '#fef3ff',
top:'88',
});
var tableCategoryData = [];
while(i<answer.QuestionList.length)
{
var label = Ti.UI.createLabel({
text:answer.QuestionList[i].CategoryTitle,
color : '#000000',
font:{
color:'#000000',
fontSize:'20sp',
},
textAlign:Ti.UI.TEXT_ALIGNMENT_LEFT,
left : 13,
top:'10dp',
});
var rowouter = Ti.UI.createView({
bottom:'10dp',
touchEnabled: true,
height:Ti.UI.SIZE,
backgroundColor:'#fef3ff',
});//Andris
var row = Ti.UI.createTableViewRow({
className: 'row',
objName: 'row',
touchEnabled: true,
height:rowouter.height,
color: "#000000",
font : {
color : '#000000'
},
backgroundColor:'#fef3ff',
});
rowouter.add(label);
row.add(rowouter);
tableCategoryData.push(row);
++i;
}
tableList.setData(tableCategoryData);

Adding number to label on swtichclick in titanium

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

How do you retrieve photos from Titanium Cloud?

I'm a newbie in Titanium and web development. I uploaded some images to the Titanium Cloud Service (ACS) and wanna display them on my app. Below is my code. It runs, but I don't see any photos except for the title and back button. Can someone take a look at my code and give me some hint on what I'm missing? Thank you for your time!
//Import the module
var Cloud = require('ti.cloud');
Cloud.debug = true; // optional; if you add this line, set it to false for production
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
exports.getAlbumWin = function() {
//create window
var album_window = Titanium.UI.createWindow({
backgroundColor:'#FFF',
title: "Travel Diary"
});
//create title
var title = Titanium.UI.createLabel({
text: "All Trip Photos Submitted by Our Users",
top:10,
color: '#008000',
textAlign: 'center',
font: {fontSize:50}
});
var tableView = Ti.UI.createTableView({
top: '5%',
scrollable: true,
width: '100%',
minRowHeight: '500',
bottom: '10%',
});
//Get diary entries, add them to the table view and display it
Cloud.Photos.query({
page: 1,
per_page: 10
}, function(e) {
var row, dateLabel, placeLabel, reviewLabel;
var displayData = [];
if (e.success){
alert('Count: '+e.photos.length);
for (var i=0; i<e.photos.length; i++) {
var photo = e.photos[i];
var image2 = photo.urls.square.toImage();
//create imageView
var photoView = Ti.UI.createImageView({
image: image2
});
//photo.urls.square
displayData.push(photoView);
}
tableView.setData(displayData);
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
//add a 'back' button
var back_button = Titanium.UI.createButton({
title: "Back",
height:160,
left:40,
right:40,
bottom: '0%'
});
//Add Event Listener
back_button.addEventListener('click', function(){
//call an export function
var win = require('home').getHomeWin;
//create new instance
var nextWin = new win();
nextWin.open();
});
album_window.add(title);
album_window.add(tableView);
album_window.add(back_button);
return album_window;
};
In appcelerator docs you can see what is image property of a Ti.UI.imageView,
image : (String/Titanium.Blob/Titanium.Filesystem.File)
Image to display, defined using a local filesystem path, a File
object, a remote URL, or a Blob object containing image data. Blob and
File objects are not supported on Mobile Web.
So you could, use url as it is.
Try like this,
var image2 = photo.urls.square_75;
(Use as this unless you have specified a Custom Photo Size named square).
Look here for more information about "urls" property of Cloud photo object.

Titanium - How to display Month-Date-Year Only

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"

textField in listView

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.

Categories

Resources