Titanium Appcelerator
unable to update text inside listview code on button click below:
{
type : 'Ti.UI.View',
bindId : 'vwqtySelection',
properties : {
top : '30dp',
height : '50dp',
//backgroundColor: 'red',
width : require('main').XhdpiSupport(150),
right : '90dp',
zIndex : 10
},
childTemplates : [{
type : 'Ti.UI.Button',
bindId : 'btnMinus',
properties : {
left : '15dp',
color : '#676972',
title : '-',
width : require('main').XhdpiSupport(30),
height : require('main').XhdpiSupport(22),
}
}, {
type : 'Ti.UI.Label',
bindId : 'qtyValue',
properties : {
//touchenabled : false,
left : '50dp',
color : '#676972',
text : '4',
textAlign : 'center',
}
}, {
type : 'Ti.UI.Button',
bindId : 'btnPlus',
properties : {
left : '79dp',
color : '#676972',
title : '+',
}
}]
}
> Itemclick selection where to update text on button click
wants to update text on button click i.e. 4 to 2
below code i tried
scrlView.addEventListener('itemclick', function(e) {
if (e.bindId === 'btnMinus') {
item = section.getItemAt(e.itemIndex);
e.section.qtyValue.properties.text = "2";
e.section.updateItemAt(e.itemIndex, item);
//here not able to update text 4 to 2
} else if (e.bindId === 'btnPlus') {
}
}};
error getting below
Message: Uncaught TypeError: Cannot read property 'properties' of undefined
This is an example of how to edit a UI element in a listView.
Each ListItem contains a Label that includes a number and a plus label, when you click on the plus label, it should increment the number in that listItem.
index.xml file:
<ListView id="listView" class="listView" defaultItemTemplate="template">
<Templates>
<ItemTemplate name="template" layout='horizontal'>
<Label bindId="number" id="number" left=20>0</Label>
<Label bindId="add" id="add" right=20 onClick="addOneToCurrentNumber">+</Label>
</ItemTemplate>
</Templates>
<ListSection>
<ListItem number:text='0' />
<ListItem number:text='-50' />
<ListItem number:text='100' />
<ListItem number:text='1024' />
</ListSection>
</ListView>
index.js file:
function addOneToCurrentNumber(e) {
var row = $.listView.sections[0].getItemAt(e.itemIndex);
var number = parseInt(row.number.text);
number++;
row.number.text = number;
$.listView.sections[0].updateItemAt(e.itemIndex, row, { animated:true });
}
Hope this helps, please let me know if you needed any modifications.
Related
I'm trying to load a JPG image from my local folder in my react-native application.
The image is stored inside assets folder which I''m trying to render inside Image tag
Here's my JSON object
{
title: 'Device 2',
image: '../assets/imgs/device_default.jpg',
cta: 'View device',
mac: '1234-xxxx-xxxx-5678'
},
Here's my code for the same
<Block flex style={imgContainer}>
<Image source={{uri: item.image}} style={imageStyles} />
</Block>
here item contains the props value. I can iterate other values like title and mac
but not able to render the image.
Can anyone help me on this??
JSON
title: 'Device 2',
src : require('../assets/imgs/device_default.jpg'),
cta: 'View device',
mac: '1234-xxxx-xxxx-5678'
},
HTML
<Block flex style={imgContainer}>
<Image source={item.src} style={imageStyles} />
</Block>
Got the exact solution here
dynamic paths in require are not currently supported.The only allowed way to refer to an image in the bundle is to literally write require('name-of-the-asset') in the source.
you need to add require for image in your json.Check below example
const Profiles=[
{
"id" : "1",
"name" : "Peter Parker",
"src" : require('../images/user1.png'),
"age":"70",
},
{
"id" : "2",
"name" : "Barack Obama",
"src" : require('../images/user2.png'),
"age":"19",
},
{
"id" : "3",
"name" : "Hilary Clinton",
"src" : require('../images/user3.png'),
"age":"50",
}
]
export default Profiles;
I want to bind click event inside webview
Below is my code but its not working.
_renderContent() {
var s = '';
if(this.state.contents.length > 0) {
this.state.contents.map(( guid, i) => {
s += '<div style="font-size:48;padding-left:10px;"><button onClick = alert("hi");>try<button></div>';
});
return (
<WebView
source={ { html: s} }
scalesPageToFit={true}
startInLoadingState={false}
/>
);
}
}
What happens if you close your button tag properly and maybe wrap your alert('hi') in quotes?
<div style="font-size:48;padding-left:10px;"><button onClick="alert('hi')";>try</button></div>
I have a question about scrollview for appcelerator titanium, I want to scroll labels inside scrollview:
scrollpage.xml
<View id="content" layout="vertical" top="100dp" width="100%">
<ScrollView contentWidth="Ti.UI.SIZE" contentHeight="Ti.UI.SIZE" top="10dp" id="svc" height="48dp" backgroundColor="#ff0000" >
</ScrollView>
</View>
</Window>
scrollpage.js
for ( i = 0; i < 19; i++) {
var scrollLabel = Ti.UI.createLabel({
width : Ti.UI.SIZE,
height : '40dp',
font : { fontSize : 14 },
color:'#000',
text : 'Portfolio'+i,
id:'label_'+i,
});
$.svc.add(scrollLabel);
}
The result
I tried ScrollableView but I want many items showing directly on screen.
My aim is to achieve this :
Please explain what did I do wrong! Thank you!
That's because by default the layout of a ScrollView is composite. So, if you want different layout, add layout="horizontal" on your ScrollableView to place your child element :
<ScrollView contentWidth="Ti.UI.SIZE" contentHeight="Ti.UI.SIZE" top="10dp" id="svc" height="48dp" backgroundColor="#ff0000" layout="horizontal"></ScrollView>
More information here about layout : http://docs.appcelerator.com/platform/latest/#!/guide/Layouts,_Positioning,_and_the_View_Hierarchy-section-29004895_Layouts,Positioning,andtheViewHierarchy-Layoutmodes
I am working on an app for iphone and android. I want to allow user to login using google plus and linked as well. I have the GoogleAuth.js and m using it but i want to use google's signin button .
What i have done is i downloaded assets from google's branding page and used them in TSS. But there is an Google+ iOS module on Google's developer website. Haven't found more than the rest api for LinkedIn. It can wait though.
Alloy view
<Alloy>
<Window class="container" title="Log In">
<TextField id = "txtUsername" hintText = "Username"/>
<TextField id = "txtPassword" hintText = "Password" passwordMask = "true"/>
<Button id = "btnEmailLogin" title = "Login" onClick = "loginWithEmail"/>
<Label id = "lblOrText" text = "OR"></Label>
<LoginButton id = "btnFacebookLogin" ns = "Alloy.Globals.Facebook"/>
<Button id = "btnGoogleLogin" onClick = "loginWithGoogle" />
</Window>
</Alloy>
TSS :
".container": {
backgroundColor:"white"
},
"#txtUsername":{
top:40,
width:"90%",
left:"5%",
height:32,
borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color:"black",
font:{fontFamily:"Helvetica",fontSize:15}
},
"#txtPassword":{
top:80,
left:"5%",
width:"90%",
height:32,
borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color:"black",
font:{fontFamily:"Helvetica",fontSize:15}
},
"#btnEmailLogin":{
top:120,
left:"20%",
width:"60%",
height:44,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
color:"black",
backgroundGradient: {
type: 'linear',
startPoint: { x: '0%', y: '0%' },
endPoint: { x: '0%', y: '100%' },
colors: [ { color: '#5FDAFC', offset: 0.25 }, { color: '#06ADDB', offset: 1.0 } ],
}
},
"#lblOrText":{
top:170,
width:"auto"
},
"#btnFacebookLogin":{
top:200,
},
"#btnGoogleLogin":{
backgroundImage:"images/Red-signin-Long-base-44dp.png",
width:246,
height:44,
top:250
}
CONTROLLER :
/* CODE for Fb login before this */
var GoogleAuth = Alloy.Globals.GoogleAuth;
var googleAuth = new GoogleAuth({
clientId : '1XXXXxxxxxxxxxxxxxxxxxxxxxxx',
clientSecret : 'secretsecretsecret',
propertyName : 'profile',
scope : ['https://www.googleapis.com/auth/plus.login']
});
function loginWithGoogle(){
googleAuth.authorize();
}
In my Sencha application i am showing a web page with iframe . When i scroll iframe's content it's container panel is also scrolling with it . Due to it sometimes iframe is not scrolling properly . Is there any need to changes in style/css of iframe or panel..?
Code :
Ext.define('Example.view.Dashboard', {
extend : "Ext.Panel",
alias : "widget.dashboard",
config : {
layout: 'vbox',
scrollable : false,
hideAnimation : {
type : "slideOut",
direction : 'down',
duration : 500
},
showAnimation : {
type : "slideIn",
direction : 'up',
duration : 500
},
},
initialize : function() {
this.callParent(arguments);
var cancelButton = {
ui : "normal",
handler : this.onBackButtonTap,
scope : this,
id : 'cancelDashboardButton',
itemId : 'cancelDashboardButton',
cls : 'button-left-arrow',
};
var topToolbar = {
xtype : "titlebar",
docked : "top",
cls : 'header',
name : 'detailToolbar',
title : "Dashboards",
itemId : 'dashboard-title',
items : [cancelButton]
};
var bottomToolbar = {
xtype : "toolbar",
docked : "bottom",
cls : 'footer',
};
this.add([topToolbar,
{
xtype : 'panel',
itemId:'webContainer',
flex:50,
html : '<div style="-webkit-overflow-scrolling:touch; height: 1000px; overflow: auto;"><iframe src="http://www.metacube.com/" border="0" frameborder="no" style="height:100%;width:100%;"> <iframe/></div>',
},
bottomToolbar]);
},
Maybe you can listen for a dragstart event on the nested iframe and then call the event stopPropagation method on the handler. This should prevent event to propagate to the parent container and scroll it too.