Add list parameter to method (Extension)

I am learning to make extensions.

How do I add a list parameter to a method?

I am following this tutorial and trying to do the challenge in the last.

I believe you know java, as what your profile says.
In whatever public method with the annotation @SimpleFunction, its parameter will be added to the block. Bear in mind that it will try to convert to the datatype you are specifying, so don’t try to put something like java.io.File.

@WatermelonIce

If I put ArrayList as a parameter will it work as I have done it and it is also compiling successfully but when I am running the app it is not working.

Here’s my code I changed. It takes List as input from java.util package and then converts it to a primitive int array and passes it to a GradientDrawable object but the app does not show the gradient color.

 @SimpleFunction(description = "")
    public void SetGradientBackground(AndroidViewComponent component, Object orientation, List<Integer> integers) {
        try {
	    View view = component.getView();
		
        int[] ret = new int[integers.size()];
		Iterator<Integer> iterator = integers.iterator();
		for (int i = 0; i < ret.length; i++)
		{
    		ret[i] = iterator.next().intValue();
		}
		
        GradientDrawable gradientDrawable = new GradientDrawable(
                (GradientDrawable.Orientation) orientation,
                ret);

        view.setBackground(gradientDrawable);
    } 
    catch(Exception e) {
        ErrorOccured(e.getMessage());
    }        
}

this should be int[]

@luv.ak.tech
It does not work :pensive:

For some reason, I tested it and it worked too! I guess app-inventor supports that also :wink:

After changing List<Integer> to int[] I am not able to compile the extension using Apache ANT

where did you get the code?
And did you try to create a gradient from the input color to YailList?

Use YailList.

No, you can’t pass arrays as parameter.
Either you will have to convert it to object or parse from string.

Also you should ask your question in AI2 community.

@Kenin

How to use YailList?

Is it same as ArrayList and is in java.util?

@Kenin
I am making extension for kodular

@Salman_Dev

From Stack overflow

1 Like

Check the ai2 sources to learn more about it.

In parameters give there YailList list for getting a list in kodular

Yail List is in any package as when I am doing YailList list it is giving error - Cannot find symbol

Show your code here let me check

@SimpleFunction(description = “”)
public void SetGradientBackground(AndroidViewComponent component, Object orientation, YailList list) {
try {

		View view = component.getView();


        GradientDrawable gradientDrawable = new GradientDrawable(
                (GradientDrawable.Orientation) orientation,
                list);


        view.setBackground(gradientDrawable);
    } 
    catch(Exception e) {
        ErrorOccured(e.getMessage());
    }        
}

Show your code and error’s screenshot

The code and two errors.