Identify container of an object

Hi,
I’m using an “any button click” block to trigger a button press from a cloned row.
I want to change the background color of the row where the button is placed but I can’t find out how.
I search for something like:
“Set the background color to RED of the ROW that conain the pressed button.”
I’m starting with this but obviously is wrong.


Thank you

Hi there,

What you’ll need to do is:

  • For each Column on your Screen, check if this Column contains your Button
  • If it does, change this Column’s background color

You can see blocks to do this in this screenshot, and a demo project here.

Let me know if you have any questions about how this works!

5 Likes

So, no way without polling every element?
No way to know the “owner” of an object?

This is my final solution:
image
Even if I don’t like so much to check every element to know the owner. At the moment is not a problem 'cause I have only few rows, but If the number of rows get bigger and I have to change the status of the last one it could take a while to apply changes.

1 Like

An alternate approach that /might/ be faster.

Make a list of ‘all row in column’. Then make a list of the first button in each column. Use the ‘find in list’ to find the button’s list position, then use that list position to get the row’s component ID using a list block.

Oh, wait. If you need to loop through every row to change the color /anyway/, you probably aren’t going to gain time by finding the right row with list blocks.

3 Likes

Actually, I bet you don’t need to change color on all those rows. You only need to change ONE row back to white. You could set a variable to that row’s ID on the previous pass, and just change it.

I’m betting that’s going to be faster.

Here’s a demo project - waiting for 100 rows to clone is painfully slow (not related to my solution), but then the response to button pressing is fast.
https://x.thunkable.com/copy/bb5318a12f8cc3df4de693190f0c5782

If you’re checking performance on a slower device, wait until it finishes cloning first. It takes my 2016 iPhone /forever/ to finish.

I added timing for both approaches. If you click a label, it iterates through them. For 100 rows (slow iPhone/Live) with iterating (click the label), ~500ms. For 100 rows (same conditions but using list functions - click a button): ~20 ms. Your results will vary (your phone might be faster), but that’s a noticeable difference with 100 rows.

Got a list with 5 rows? Do whatever you want. :slight_smile: It probably doesn’t matter much.

SLOW:
image

FAST:

Setup to go fast:

I tested on web view also (fast computer). List functions ~1ms, iterate ~50ms.

3 Likes

Take note.

The truth is that I was unaware of the existence of the clone method but I am going to test it in a solution that I am working on because I am having speed problems.

Very interesting your functions that are giving me new ideas.

2 Likes

Cloning is probably not a solution to a speed problem. :slight_smile:

4 Likes

Can we put that on the Thunkable quote board, if there is one? :grin:

3 Likes

I use a screen with 10 rows designed that I hide / show / fill depending on the amount of data and current page, with controls put in lists stored in memory and using functions with indexes to fill them directly.

I don’t know if my system works better … but I have to give it a try

1 Like

If there is one, the most popular quote would be ‘Please do not reply to a post that is 2 years old!’

2 Likes