About returning Lists in extension

Could you please tell me how to I return Lists in App Inventor Extensions ?

I searched in the community and got to know about YailList, but I know nothing about it.

To be more precise of what I want to do,

I want to return a List of numbers (int values).
First, I'd make an empty List, then I'll add components in a loop. At last, I'd return the List.

Could you give me an example showing such a process ?

What do you mean for return the list ?

1 Like

I mean that I want to return a List, the light blue color built-in block set, which allows us to store multiple data under one single variable.

The easy way is to check the source code of app inventor.
TinyDB gettaglist will return a list, maybe that can help.

1 Like

How about taking a look at this?

https://ullisroboterseite.de/AIComponentsDoc/classcom_1_1google_1_1appinventor_1_1components_1_1runtime_1_1util_1_1_yail_list.html

1 Like

Thanks for this. I'll read it.

But till then could you give a quick example of returning a YailList of numbers ?

Does the YailList.makeList(Object[] objects) take only object arguments ?

I have learnt from my Java teacher that int values are not objects.

I think:

  • turn an array of Objects into an array of booleans/Strings/ints...

  • then, turn the array into a YailList.

1 Like

Do you think that this will work ?

public YailList test(){
     List a = new ArrayList<Integer>();
     Integer i = 0;
     
     for(i = 0; i < 5; i++){
       a.add(i);
     }
     
     YailList yl = YailList.makeList(a);
     return yl;
}

Why not try it out and compile it?

1 Like

You could try:

return Arrays.asList(1,2,3,4,5);
2 Likes

That will take a huge amount of time for me.

Cuz the steps for me :

  1. Open Niotron IDE.
  2. Paste the Code there. Due to auto-indent, there will bw a pattern of spaces.
  3. Remove the spaces by hundreds of Find/Replace actions.
  4. Compile the extension.
  5. Open AppInventor.
  6. Start a new Project.
  7. Import extension.
  8. Set up all the blocks. (Probably takes 4-5 mins for me.)
  9. Compile the app. (Takes 3-4 minutes for me.)
  10. Download the app. (Fast)
  11. Install the app. (More than a minute.)
  12. Open and test it and get to the conclusion.

If anything is wrong, I've to loop all the steps again.
Which will take me hours.
And I've lots of stuff to do in my life.
But I want to complete this extension ASAP.

So I need help.
(I can't use a Companion for Do it s sadly. :cry: )

I can't hard code the thing. But i'll still try to compile the extension and figure out if its working.

I'm getting an compile-time error when I'm trying this part of the code.

YailList yl = YailList.makeList(a) where a is List of Integer objects.

return yl; <- This part has an error.

Error Image





Test Code Image


Pls help...

Sorry, I found out the problem for the previous error.
It was in the return type. I was just modifying the TestFunction() generated by Niotron. But I forgot to change the return type. Sorry again.

I've tested it and it is working, thanks @Gordon_Lu for providing the link (in the post that I marked the solution).

It helped me to get the YailList.makeList() method.

1 Like

When I tried to directly return List<Integer>, it still worked. :smiley:

So I'd rather return a List<Integer> instead of a YailList from next time. Bye :wave:t2:

Then let me suggest you to fix this
Using the community to debug your blocks takes even more time...

use Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools
Taifun


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

1 Like

I said you before that I can't use a Companion right now... :cry: But I'd be able to use it after a week or two.

If this is because you do not have a Android phone, you can install Android emulator on computer and install companion in the emulator.

1 Like