Add list parameter to method (Extension)

You have not imported the yaillist class in your extension so the error is causing
Use an IDLE like VS code or intelliJ
Using texteditor your work increases

From where to import it?

I have already imported java.util.*

this topic has just been released, hmm something strange

The YailList is an app Inventor, and not java class , in the package com.google.appinventor.components.runtime.util, so it’s import would be com.google.appinventor.components.runtime.util.YailList

4 Likes
  1. import com.google.appinventor.components.runtime.util.YailList;
  2. import com.google.appinventor.components.runtime.util;
    add these 2 lines
  3. replace ur code

@SimpleFunction(description = “this block is where u put ur component,colors,u may have dout what is orientation it is where u put the green block i gave in gradients section”)
public void SetGradientBackgroundcolor(AndroidViewComponent component, Object orientation, YailList colors) {

// To set gradient colors as background, what we are actually going to
// do is create a new GradientDrawable object and set it as
// the background of the view. With this approach, it’d be possible to
// create gradients programmatically without editing the manifest
// file which is currently not supported in App Inventor 2.

// Getting the reference to the View of the parameter component using
// the getView() method of AndroidNonVisible class.
View view = component.getView();

// GradientDrawable is a subclass of Drawable class from Android
// support library. It is mostly used to create gradients.
// For more info visit: https://developer.android.com/reference/android/graphics/drawable/GradientDrawable
int array = new int[colors.size()];
int index = 0;
for(String e : colors.toStringArray()) {
array[index] = Integer.parseInt(e); index++;
}

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

// Setting the gradientDrawable as the background of view.
view.setBackground(gradientDrawable);
}

ur done this is total code for list

2 Likes

@electrobot_appy if you want to share code in the community you should make it like this :

```
//your code here
```

Result :

    //your code here
3 Likes

Thank you everybody!

Finally it is solved!

:smiley:

How can i ask list in extension - Extension Development - MIT App Inventor Community this is were i got solution as i was wrking on same goal

1 Like

Sorry, I didn’t say that. I was saying java.util.ArrayList is a possible type. I think I have discussion with @Mohamed_Tamer before. I understand using YailList is best.

1 Like

@WatermelonIce

:thinking:

Looks like I mis-posted.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.