Click event on a Button created with DynamicComponents

Please help me.
How do I create a code block to get a click event on a dynamic component that has been created using the click tools.

2 Likes

Store the Component that you've created in a variable. Invoke the When Button.Click (under Any Components) event on that component:
image

I will try it

did it work? if it worked, please click solution.

What I mean is different from what was conveyed by @nishyanthkumar So far I haven't found the answer.

please do not spam the community and be patient until you get an answer...
Taifun

1 Like

Using the DCLite extension by KevinKun

(you probably do not need ClickTools....)

4 Likes

Thanks @TIMAI2, I'll give it a try

1 Like

Thanks @TIMAI2 , problem solved

1 Like

Do you need to make a static invisible button on the screen first so that you can use "when anybutton.click" and the green button1? Thanks

With DCLite a real button was required yes.

This gives access to the anycomponent blocks, which are needed.

this can be a string 'Button'

1 Like

or button, works for me as well...

2 Likes

First Thanks a lot for your great extension. Regarding your response, are you saying that the green "button1" does not need to be the one dragged from button component, it can simply be a string containing the base word 'button' or 'Button' (maybe they are the same)? In addition, in examples, we see only one dynamic button used. I wonder how convenient it is to use it for multiple components e.g. let's say a few dynamiclly generated layouts, each containing a label, a list picker and a button. Using DCLite, i would think, the first thing is to get the number of layouts i need to make, then initialize that number of lists. Then for each layout, i dynamiclly generate a label, listpicker and button so that all these dynamiclly generated items are put in a list. Then when a button is clicked, I get the name of the button, then look up which list contains this clicked button, then I get the listpicker value from that list. Is there an even simpler approach using DCLite for this purpose?

Thanks for confirming

You may want to use the main dynamic components extension for what you intend, you then can generate id's for each component and use them for selection in the any component blocks.

that's what i am trying, i have ids in the format of e.g. button2 (2 indicate the 2nd layout). is there a way to extract the number from a number-containing-string in App inventor?

AI2 will treat numbers as strings and strings as numbers automagically, but you can always check with the isNumber block on a string. If this returns as false then edit the string and/or multiply by 1.

oh, just see your post in another post to remove letters from a string. Thanks!

Why won't you use dynamic extension by @yusufcihan ? For example

1 Like