Just add this code, then do:
You're trying to take list input from the user and turn it into gradient right?
yes
but its just sample code its not main extension i will use for future purpose
my code
int[] array = new int[list.size()]; int index = 0;for(String e : list.toStringArray()) { array[index] = Integer.parseInt(e); index++; }
GradientDrawable gradientDrawable = new GradientDrawable(
(GradientDrawable.Orientation) orientation, array);
my error
[javac] C:\Users\GOD\appinventor-sources\appinventor\components\src\edu\hifiapps\Gradient\Gradient.java:50: error: cannot find symbol
[javac] int[] array = new int[list.size()]; int index = 0; for(String e : list.toStringArray()) { array[index] = Integer.parseInt(e); index++; }
[javac] ^
[javac] symbol: variable list
[javac] location: class Gradient
[javac] C:\Users\GOD\appinventor-sources\appinventor\components\src\edu\hifiapps\Gradient\Gradient.java:50: error: cannot find symbol
[javac] int[] array = new int[list.size()]; int index = 0; for(String e : list.toStringArray()) { array[index] = Integer.parseInt(e); index++; }
[javac] ^
[javac] symbol: variable list
[javac] location: class Gradient
How can that error occur? It should NOT occur.
i think it is because the ; is nearby it should be in each line end see my code
![]()
I thought it's occured for Integer.parseInt
my mistake ![]()
Can you please post you're new code?
i posted and once more do u need as text or image
Just wait, i will give you detailed example.
i got answer from u when it wrk in app i will explain wait
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());
}
yes ![]()
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);
}
this might wrk i will also try it thanks a lot
please see it
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 :
- Windows = Ctrl + F
- Mac = Command + F
i even do the same any way ths
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.