PDA

View Full Version : Onclick in subview


uppal
04-20-2006, 06:02 PM
Hi

I'm creating a dynamic text view using new LzText(parentviewname);

& I want to make the each view respond with its identity on click ..

so I have a onclick method defined in the


-----------------------------------------------
<view name="parentviewname">

<method event="onclick">
Debug.write("index " , this.subviews);
for(var i=0; i < this.subviews.length; i++)
{
Debug.write("subview: " + this.subviews[i].getText());
}
</method>
<view>
------------------------------------------------
the problem is each & every time when i click on the newly created text item, the onclick ,ehod is called.... but how can i detect that what text item is clicked ? say out of 20 such texts...

thanks
Uppal

vichai
04-20-2006, 08:56 PM
You have to create new class inherited from LzText

----------
<canvas debug="true">
<text>Test</text>
<class name="clsText" extends="text">
<attribute name="myId" type="number"/>
<method name="textClick" event="onclick">
Debug.write( this.myId ) ;
</method>
</class>
<view name="parentviewname">
<simplelayout axis="y" spacing="10"/>
<attribute name="subviews"/>
<attribute name="nCount" type="number" value="0" />
<method event="init">
this.subviews = new Array(20) ;
</method>

<method event="onclick">
<![CDATA[
// Debug.write("index " , this.subviews);
for(var i=0; i < this.subviews.length; i++) {
Debug.write("subview: " + this.subviews[i].getText());
}
]]>
</method>
<button>create text
<method event="onclick">
<![CDATA[
var nCount = parent.nCount ;
if( nCount < 20 ) {
var oText = new clsText( parentviewname ) ;
nCount = parent.nCount++ ;
this.subviews[ nCount ] = oText ;
oText.setAttribute( "myId" , nCount ) ;
oText.setText( nCount ) ;
}
]]>
</method>
</button>
</view>

</canvas>

----------

monkeytroy
08-29-2007, 10:53 AM
Thanks so much for this reply.. I know it's old but is exactly what I needed to solve a problem I was having.