@Alpha2020 Here you go
For Get List :
import com.google.appinventor.components.runtime.util.YailList;
import java.util.ArrayList;
import java.util.List;
................
.........
..............
@SimpleFunction(description = "")
public YailList GetList() {
List listItems = new ArrayList();
listItems.add("Text1");
listItems.add("Text2");
listItems.add("Text3");
return YailList.makeList(listItems);
}
1 Like
Thank you very very much.....
1 Like
You're welcome @Alpha2020
1 Like
Note that you can also return type List<> directly, for example:
public List<String> GetItems() {
return Arrays.asList("Item1", "Item2", "Item3");
}
The App Inventor runtime will take care to ensure that every value returned in the list is coercible to a valid type in the blocks editor.
If you return YailList, you are expected to ensure that every item in the list is valid.
3 Likes
Okay, Thank you Mr. @ewpatton
1 Like
TIMAI2
February 22, 2022, 4:35pm
46
Sorry to drag this one up from the deep.....
ewpatton:
Note that you can also return type List<> directly, for example:
public List<String> GetItems() {
return Arrays.asList("Item1", "Item2", "Item3");
}
The App Inventor runtime will take care to ensure that every value returned in the list is coercible to a valid type in the blocks editor
Is it possible to return a list of lists (list of pairs)? For example like this:
return Arrays.asList(("Item1",1), ("Item2",2), ("Item3",3));
My IDE doesn't like the syntax....
maybe? -
return Arrays.asList(Arrays.asList("Item1",1), Arrays.asList("Item2",2), Arrays.asList("Item3",3));
Hope i did not misunderstood your question or gave a incorrect answer
1 Like
TIMAI2
February 22, 2022, 4:45pm
48
Well the IDE likes it, will have to build and see what comes back
1 Like
TIMAI2
February 22, 2022, 4:53pm
49
and it comes back as a list of lists
@SimpleProperty(description = "list of mimetypes")
public List Mimetypes() {
return Arrays.asList(Arrays.asList("PNG", "image/png"),Arrays.asList("JPG", "image/jpg"),Arrays.asList("BMP", "image/bmp"));
}
(only problem is, have you seem how long the mimetypes list is - not really a problem, I will need to use find and replace anyway)
1 Like
If you have the mime list as a CSV file you could read it into the extension and pass its contents through CsvUtil.fromCsvTable
(which is the what the list from csv table block does).
2 Likes
TIMAI2
February 22, 2022, 6:24pm
51
Like so ?
@SimpleProperty(description = "list of mimetypes")
public List Mimetypes() {
return CSvUtil.fromCsvTable("PNG", "image/png"\n"JPG", "image/jpg"\n"BMP", "image/bmp");
}
TIMAI2:
Like so ?
No , there should be no extra parameters you need a string just a string as parameter. I dont use csv much so idk what to do here.