I'm building an app in appcelerator studio and I use alloy.
I want to insert a data in my TableView from my controller.
So this is my .xml class
<Alloy>
<View class="container" >
<TableView id="table" class="table">
<TableViewSection id="table" >
</TableViewSection>
</TableView>
<!-- <Button id="button" onClick="doClick"></Button>-->
</View>
</Alloy>
This is the code of my controller
var view1 = Ti.UI.createView({
left : 0,
width : "35%",
top: "30px"
});
var view2 = Ti.UI.createView({
left : "35%",
width : "25%",
top: "30px"
});
var view3 = Ti.UI.createView({
left : "60%",
width : "25%",
top: "30px"
});
var view4 = Ti.UI.createView({
left : "85%",
width : "15%",
top: "30px"
});
view1.add(createHeader(L(lang+"social_history")));
view2.add(createHeader(L(lang+"start_date")));
view3.add(createHeader(L(lang+"end_date")));
view4.add(createHeader(L(lang+"quantity_um")));
var row = Ti.UI.createTableViewRow();
var rowData = [];
row.add(view1);
row.add(view2);
row.add(view3);
row.add(view4);
rowData.push(row);
$.table.data=rowData;
for(var i=0; i<3; i++){
var myRow = Ti.UI.createTableViewRow({
id: 'overview',
height: '47dip'
});
var myLabel = Ti.UI.createLabel({
text: 'Overview',
top: "0dip",
height: "47dip",
left: "5dip",
right: "5dip",
font: {
fontSize: "14dp",
fontWeight: "bold"
}
});
myRow.add(myLabel);
// this is working, but directly after displaying this row,
// the collection is overwriting it again
$.table.appendRow(myRow);
}
function createHeader(headerText){
var heading = Ti.UI.createView({
backgroundColor : "#0c7b84"
});
var headingText = $.UI.create("Label", {
classes: 'headerTableLabel'
});
headingText.text = headerText;
heading.add(headingText);
return heading;
}
Now in the for cycle, I want to insert 3 row in my table, but if I try to running my application I can't see these other row.
How can I fixed it?
You should try to use an controller instead of creating the row in JS since you are using Alloy, like:
row.xml
<Alloy>
<TableViewRow id="row">
<Label id="title"/>
<ImageView id="icon"/>
</TableViewRow>
</Alloy>
row.js
var args = arguments[0] || {};
$.row.myValue = args.title;
$.title.text = args.title;
$.icon.image = args.icon;
table.js
var data = [];
var yourArray = [
{title:'england',icon:'en.png'},
{title:'portugal',icon:'pt.png'},
{title:'france',icon:'fr.png'}
];
for(var i in yourArray) data.push(Alloy.createController('row',{
title:yourArray[i].title,
icon:yourArray[i].icon
}).getView());
$.table.setData(data);
When you add the row (appendRow) the previous TableView data disappears? That's weird, you could do this as a workaround:
data.push(Alloy.createController('row',{
title:'spain',
icon:'es.png'
}).getView());
//data.length = 4
$.table.setData(data);
Get the row data:
$.table.addEventListener('click',function(e) {
selected_index = e.index;
selected_row = e.row;
selected_my_value = e.row.myValue; //see the alloy row controller
});
API Docs: TableView
Related
I am trying to get the height of the actionbar in pixels or DIPS.
I can only ever return 0;
<Page class="page"
navigatingFrom="onNavigatingFrom"
navigatingTo="onNavigatingTo"
xmlns="http://schemas.nativescript.org/tns.xsd">
<ActionBar id="actionBar" class="action-bar theme-action-bar">
function onNavigatingTo(args) {
var actionBar = page.getViewById("actionBar");
var height = actionBar.getActualSize().height;
//or
var height = actionBar.height;
}
Try adding a timeout,
function onNavigatingTo(args) {
var actionBar = page.getViewById("actionBar");
setTimeout(()=>{
var height = actionBar.getActualSize().height;
}, 100);
}
I would like to draw a line binding a entity to its label with an offset.
CesiumJS allows to offset the label, however its not possible to draw a line (or polyline) from a position to an offset like the red line in this image.
How can i do it? any sugestion?
i'm using pixel offset. but there is no problem to use eye offset
labels.add({
position: Cesium.Cartesian3.fromDegrees(-75.1641667, 29.9522222),
text: 'Another label',
pixelOffset: new Cesium.Cartesian2(100,-100)
});
The best way to do this is probably a billboard with an image of the line on it. The length will never change if it's a pixelOffset. You can put an image of a white line, and use the color property to set any other color.
var viewer = new Cesium.Viewer('cesiumContainer', {
navigationInstructionsInitiallyVisible: false, animation: false, timeline: false,
// These next 6 lines are just to avoid Stack Snippet error messages.
imageryProvider : new Cesium.TileMapServiceImageryProvider({
url: Cesium.buildModuleUrl("Assets/Textures/NaturalEarthII"),
}),
baseLayerPicker : false,
geocoder : false,
infoBox : false
});
var scene = viewer.scene;
var offsetX = 50, offsetY = -80;
var pos = Cesium.Cartesian3.fromDegrees(-75.1641667, 29.9522222);
var labels = scene.primitives.add(new Cesium.LabelCollection());
labels.add({
position: pos,
text: 'Another label',
pixelOffset: new Cesium.Cartesian2(offsetX, offsetY)
});
var canvas = document.createElement('canvas');
canvas.width = Math.abs(offsetX);
canvas.height = Math.abs(offsetY);
var context2D = canvas.getContext('2d');
context2D.beginPath();
context2D.lineWidth = 3;
context2D.strokeStyle = '#ffffff';
context2D.moveTo((offsetX < 0) ? -offsetX : 0, (offsetY < 0) ? -offsetY : 0);
context2D.lineTo((offsetX < 0) ? 0 : offsetX, (offsetY < 0) ? 0 : offsetY);
context2D.stroke();
var billboards = scene.primitives.add(new Cesium.BillboardCollection());
var billboard = billboards.add({
color : Cesium.Color.RED,
image : canvas,
pixelOffset: new Cesium.Cartesian2(offsetX * 0.5, offsetY * 0.5),
position : pos
});
html, body, #cesiumContainer {
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
}
<link href="https://cesium.com/downloads/cesiumjs/releases/1.78/Build/Cesium/Widgets/widgets.css" rel="stylesheet"/>
<script src="https://cesium.com/downloads/cesiumjs/releases/1.78/Build/Cesium/Cesium.js"></script>
<div id="cesiumContainer"></div>
I am using kendo "diagram" control in my project to create sequence diagram. I am adding "textblock" control of kendo "diagram" to show some text.
however I want to show wrapped text value in "textblock" but it is not supported by kendo.
Please suggest me, if there is a way to support wrap text in "textblock" or any other alternate control of "diagram" that support same functionality of "textblock"
Thanks
Vipul
function visualTemplate(options) {
var diagram = kendo.dataviz.diagram;
var dataItem = options.dataItem;
var group = new diagram.Group();
group.append(new diagram.Rectangle({
width: 300,
height: 200,
stroke: {
width: 0
},
fill: "#e8eff7"
}));
group.append(new diagram.Rectangle({
width: 8,
height: 200,
fill: "#3399cc",
stroke: {
width: 0
}
}));
var layout = new diagram.Layout(new diagram.Rect(15, 0, 280, 200), {
alignContent: "center",
spacing: 4
});
group.append(layout);
var texts = dataItem.text.split(" ");
for (var i = 0; i < texts.length; i++) {
layout.append(new diagram.TextBlock({
text: texts[i]
}));
}
layout.reflow();
return group;
}
from release 2015.3
I have two views displayed in a window as follows
var topView = Ti.UI.createView({
top: 0,
height: '65%',
orientation: 'vertical'
});
var botView = Ti.UI.createView({
bottom: 0,
height: '35%',
layout: 'vertical'
});
i want to animate as follows:
when a button is clicked, topView increases to hundred percent while botView decreases to 0 percent. and the reverse happens when the button is clicked.
But i haven't found a way to do it for two views.
I hope someone can help out.
Thanks -:)
EDIT:
This is what i have done so far:
var expandFlag = false;
/* create animations */
var expandAnim_map = Ti.UI.createAnimation({
height : '100%',
duration: 300
});
var expandAnim_con = Ti.UI.createAnimation({
height: '0%',
duration : 300,
bottom:0
});
var collapseAnim_map = Ti.UI.createAnimation({
height: '65%',
duration: 300,
});
var collapseAnim_con = Ti.UI.createAnimation({
height: '35%',
duration: 300,
bottom:0
});
/* create animations */
if (expandFlag) {
botView.animate(collapseAnim_con);
topView.animate(collapseAnim_map);
expandFlag = false;
} else {
topView.animate(expandAnim_map);
botView.animate(expandAnim_con);
expandFlag = true;
}
This is irregular and not beautiful, hence i'm looking for a cleaner and smoother way to do it. Thanks.
I suggest that you animate only one view in order to get a good looking animation.
You can set a higher zIndex for the top view, and then expand and reduce only that view.
var expandFlag = false;
var topView = Ti.UI.createView({
top: 0,
zIndex: 2,
height: '65%',
orientation: 'vertical'
});
var botView = Ti.UI.createView({
bottom: 0,
zIndex: 1,
height: '35%',
layout: 'vertical'
});
/* create animations */
var expandAnim_map = Ti.UI.createAnimation({
height : '100%',
duration: 300
});
var collapseAnim_map = Ti.UI.createAnimation({
height: '65%',
duration: 300,
});
/* create animations */
if (expandFlag) {+
topView.animate(collapseAnim_map);
expandFlag = false;
} else {
topView.animate(expandAnim_map);
expandFlag = true;
}
i'm making a scrollable menu using common JS.
An item of the menu is a view that contains 2 others components :
a imageView for the icon, and a label for the text of this menu.
The comportement is strange and not the same on the android and ios simulator.
On the android, if a click is done on the label or on the imageview, that gives an : "uncaught TypeError: Cannot Read property..."
On iphone, that just don't launch anything.
If i click somewhere else (still into the view item) but not on image or on the labal, for example on an edge, that works just perfect!!
here is the code:
function menuIcons(itemTab) {
var menuMain = Ti.UI.createView({
layout : 'vertical',
backgroundColor : '#333333',
height : 125,
bottom : 10,
left : 10,
right : 10,
borderRadius : 5.0
});
var menuFirstLine = Ti.UI.createScrollView({
scrollType : 'horizontal',
contentHeight : 120,
contentWidth : 'auto',
layout : 'horizontal',
height : 120,
marginLeft : 5
});
var items = [];
var menuIconsItem = require('view/module/menuIconsItem');
for(var i in itemTab) {
var page = itemTab[i].page;
items[i] = new menuIconsItem(itemTab[i]);
(function(itemsEvent) {
itemsEvent.id = itemTab[i].id;
itemsEvent.addEventListener('click', function(e) {
Ti.App.fireEvent('main_menu_' + itemsEvent.id, {
id : e.source.id
});
})
})(items[i]);
menuFirstLine.add(items[i]);
}
menuMain.add(menuFirstLine);
return menuMain;
}
module.exports = menuIcons;
and the code of the items that is required (var menuIconsItem = require('view/module/menuIconsItem');) :
function menuIconsItem(item) {
// path for images on Android besoin de centraliser tout ca
var pathImages = '';
var itemImage = Ti.UI.createImageView({
image : item.imageLink,
width : 64,
height : 64,
top : 15
});
var itemLabel = Ti.UI.createLabel({
color : '#afafaf',
text : item.text,
font : {
textAlign : 'center'
},
height : 40,
top : 80
});
var menuItem = Ti.UI.createView({
width : 120,
height : 120,
backgroundColor : '#424242',
top : 5,
left : 5
});
menuItem.add(itemImage);
menuItem.add(itemLabel);
return menuItem;
}
module.exports = menuIconsItem;
You have to set the id for the label and image view as well.