how to use this block in extension code i get a YailList colors
from users how to get length of it,
and also how to
use this block in extension code
listt is the colors list i get index is 3
so how to use
Please explain properly.
i get a list from user where user put colours in the list and give me now how can get length of the input or length of list,how can i select item 3 of the colour list provided
the user give me this list i get it by the code
@SimpleFunction(description = "")
public void bgset(YailList colors) {
now how to get length of list,get item 3(which is yellow)
@SimpleFunction(description = "")
public Object bgset(YailList colors) {
return (colors[0]);
}
The 0 number is the index number which start from 0.
This is select list item.
For length use-
@SimpleFunction(description = "")
public int bgset(YailList colors) {
return (colors.length);
}
More information-
https://www.w3schools.com/java/java_arrays.asp
ok i will try
dint work array required but yail list found is my compile error but
converting to array works
int[] array = new int[colors.size()];
int index = 0;
for(String e : colors.toStringArray()) {
array[index] = Integer.parseInt(e);
index++;
}
int i;
int size = array.length;
for(i=0;i<size;i++){
view.setBackgroundColor((int)array[i]);
}
thanks i got help from this word
and error which says i need array
i don't know the specific error but it said
could not be used in this method
only array can work like
where i converted list to array using
Try to use list.get(index)
![](https://community.appinventor.mit.edu/user_avatar/community.appinventor.mit.edu/kumaraswamy/48/127249_2.png)
Try to use
list.get(index)
That is what is said
If you want to get size of the list use:-
listname.size()
If you want to select list item with index then use this:-
listname.get(
index
);
Hope this will help
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.