OnClick method for Dynamic Label

It is a variable dragged from ‘when.any label clicked’.

All I can see in when any Label.Click are 2 variables namely component and not already handled An example would be appreciated :slight_smile:

When you drag from component it will be get component.
ezgif.com-video-to-gif

1 Like

Yes! That’s what I’m saying. Does getComponent() return the ID only? LOL! I’m feeling like a noob :stuck_out_tongue:

EDIT 1:
When I’m trying to use the getComponent result as an ID the following error is shown. That is why I was asking for if by any way can we fetch the ID of Dynamic Label

EDIT 2:
This is a Snippet of my code. Ignore the red crosses (errors) those are caused since I created a new screen and copied these blocks without adding them. I hope this will help you understand it better that why I require the ID of Dynamic Label since the getComponent is returning a non int value and causing the above error.

EXPLANATION: I am fetching a dictionary from firebase dB and creating dynamic labels for all the keys and values(not in the blocks).

I want to:

  1. Enable click option on the the Dynamic Labels.
  2. Delete the Label which is clicked.

PS: I tried using ListViewer for the same but it displayed values in the following format (key, value) on which when I applied the click event I was not able to fetch the key name since it contained brackets and commas. Any help for the stated would be appreciated and thanks for bearing with me till now. :see_no_evil:

1 Like

No, get component doesn’t return the number, but the component instead.

And you cannot get ID by clicking the label.
If you need to the you have to use the extension by @yusufcihan

1 Like

@WatermelonIce I think I should better use Dynamic Button and making the background color as transparent. That would be easier :smile_cat:

@ExtensionDevelopers whoever can do this, since I don’t have time to… just compile and leave the AIX in this topic.

// ...
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.*;
// ...
@SimpleFunction(description = " ")
public int GetIdByComponent(AndroidViewComponent component) {
    return component.getView().getId();
}
2 Likes

Build failed


Note: I don’t know about extension developement, so if any changes are to be made then guide me.

You have removed all code of editor

@hammerhai told that compile this code so I delete all that. :grimacing::grimacing:

🤷:grin::grin::grimacing:

1 Like

com.appybuilder.kennicholsandroid.GetComponentID.aix (5.5 KB)
GetComponentID.java (1.4 KB)

4 Likes

Ohh you are faster than me. I have started build now. Appybuilder editor takes 5 minites to build :weary::weary::weary:

1 Like

I was driving or I would have uploaded it sooner:

5 Likes

com.appybuilder.vedangsolaskar2018.ExtensionCodeByStormi.aix (5.8 KB)

Here is my one

But ken won

2 Likes

Thank you so much for the code. But I guess, we still don’t have a method for whenAnyDynamicLabel.Click() also I may be wrong but whenAnyLabel.Click() won’t give you component for a click on Dynamic Label. Please let me know if I’m wrong with a suitable block, if possible.

Also thanks to @Ken and @Vedang for the quick compilation of the give code but while using the extensions following error is generated. If any further help could be provided that would be great although I did my work using Dynamic Button but since this could be a useful feature for future.

3 Likes

I thought you wanted the label to be clicked? Here you use the Dynamic Button however it likely will reproduce the same issue :thinking:

Let me take a look into the issue in the next few minutes and I will get back to you.

2 Likes

Yes! I wanted the label to be clicked. But couldn’t found whenAnyDynamicLabel.Click() Therefore just for the testing the extension, I used the Dynamic Buttons. Also as you said the error would be same in both case. Also try adding a whenAnyDynamicLabel.Click() so that we can test the above extensions on a Dynamic Label.

1 Like

No need to test since the dynamic label is composed of MakeroidDynamicLabel like MakeroidDynamicButton :) What I’m doing now is creating my own dynamic label and button extension, they will both contain the method you need.

@yusufcihan I know what you going to do, mention your extension (:

1 Like

I don’t like self-promotion but you should use my extension for that. So you won’t need to deal with using extension over a Dynamic Label component.

So you can create dynamic Labels along with other all components and use Any Component blocks if you want to set its properties and catch the events.

image

If you have a better option, go for it. I just provided an another way (and easier maybe? :slightly_smiling_face:).

4 Likes