Any label please help

I have 90 labels. I'm trying to change them all with a loop.
Can't figure out what I'm doing wrong

1 Like

You are not incrementing nmber

Make a list of all your label components, then iterate over the list, using each label's index to set its text value

image

1 Like

Repair and it still does not work

it does not work like this...
as you can see from the example by @TIMAI2 you need a list of the label components...
see also

How to work with the advanced features

A Multiple Choice Quiz: How to work with the advanced features

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like

blocks (1)

It still does not work
I'm desperate

No need to keep spamming your topic.

Did you read post 3 which gave you the solution?

You have to make a list of all your label components, then iterate over that list using the any component block.

There was a PR by @vishwas, that added every component block.

1 Like

Any news here?

xyz.kumaraswamy.tools.aix (3.7 KB)

package xyz.kumaraswamy.tools;

import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.util.YailList;
import java.lang.reflect.Field;
import java.util.ArrayList;

@SuppressWarnings("unused")
public class Tools extends AndroidNonvisibleComponent {

  public Tools(ComponentContainer container) {
    super(container.$form());
  }

  @SimpleFunction(description = "Finds all the components of the Type Given")
  public YailList ListAllComponents(String name) throws IllegalAccessException {
    ArrayList<Object> components = new ArrayList<>();

    Field[] fields = form.getClass().getDeclaredFields();
    for (Field field : fields) {
      field.setAccessible(true);
      Object object = field.get(form);
      if (object == null || !object.getClass().getSimpleName().equals(name)) {
        continue;
      }
      components.add(object);
    }
    return YailList.makeList(components);
  }
}

Hope this helps :sweat_smile:

3 Likes

It doesn't work in companion as of now.

In companion

In compiled apk works with no problem :slight_smile:

3 Likes

๋‚˜๋Š” 16์ผ ์ „์— mit app inventor๋ฅผ ์•Œ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
๋‚˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด ๋ณธ ์ ๋„ ์—†๊ณ ์š”, ๋‚˜๋Š” ๋ฐฐ์›Œ๋ณธ ์ ๋„ ์—†์Šต๋‹ˆ๋‹ค. ํ˜ผ์ž ๊ณต๋ถ€ํ•˜๋ฉด์„œ ์—ฌ๊ธฐ ์ปค๋ฎค๋‹ˆํ‹ฐ์˜ ๋„์›€์„ ๋งŽ์ด ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค. ๊ณต๋ถ€๋ฅผ ํ•˜๋‹ค๊ฐ€ 111696์™€ ๋˜‘๊ฐ™์€ ์–ด๋ ค์›€์„ ๊ฒช์–ด ๋‹ต๋ณ€์„ ์ฐพ์•„๋ดค๋Š”๋ฐ ํ•ด๋‹ต์€ ์—†๋”๊ตฐ์š”.

๊ทธ๋ž˜์„œ ํ˜ผ์ž app inventor์—์„œ ํ•ด๊ฒฐ์„ ์ฐพ์•„๋ณด๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ•ด๊ฒฐ์„ ์ฐพ์•„๋ƒˆ์Šต๋‹ˆ๋‹ค.
์ œ๊ฐ€ ์—ฌ๋Ÿฌ๋ถ„๊ป˜ ๋งŽ์€ ๋„์›€์„ ๋ฐ›์€ ๊ฒƒ์ฒ˜๋Ÿผ ์ œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์ด ์—ฌ๋Ÿฌ๋ถ„์—๊ฒŒ ๋„์›€์ด ๋˜๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.