How can i ask list in extension

Just wait, i will give you detailed example.

1 Like

i got answer from u when it wrk in app i will explain wait

1 Like

Also you can try this:

int[] array = new int[colors.size()];

        for (int i = 0; i < colors.size(); i++) {
            array[i] = Integer.parseInt(colors.get(i).toString());
        }
1 Like

yes :star_struck:
it worked actually

is answer
the main error is as said my code was like

int array = new int[list.size()]; int index = 0; for(String e : list.toStringArray()) { array[index] = Integer.parseInt(e); index++; }

as said i changed it to

int array = new int[list.size()];
int index = 0;
for(String e : list.toStringArray()) {
array[index] = Integer.parseInt(e); index++;
}

also it showed error as for the word

in the

so in my case it is
colors.size()
and so

now my final code is

@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 SetGradientBackground2color(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);

}

1 Like

this might wrk i will also try it thanks a lot

1 Like

also thanks for ur detailed explanation here @Kumaraswamy

1 Like

https://community.thunkable.com/t/extension-gradient-in-a-layout-colors-by-list/12508?u=taifun

please see it

1 Like

I just remind you and I want to give you tips, so you can create unique extensions.
Before creating an extension please check the extensions that are already available here :
https://puravidaapps.com/extensions.php

Tips for Search Extensions are available on that website :

  1. Windows = Ctrl + F
  2. Mac = Command + F

i even do the same any way ths

1 Like

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