@SimpleFunction(description = "")
public void bgset(AndroidViewComponent component,int color) {
View view = component.getView();
view.setBackgroundColor (color);
}
i am trying to set colour of horrizontal arangement
but i get error
gnu.mapping.SimpleSymbol cannot be cast to java.lang.integer
am i doing anything wrong
* indicates fully transparent and {@code FF} means opaque.
* The background color only shows if there is no background image.
*
* @param argb background color in the format 0xAARRGGBB, which
* includes alpha, red, green, and blue components
*/
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = Component.DEFAULT_VALUE_COLOR_WHITE)
@SimpleProperty
public void BackgroundColor(int argb) {
view.setBackgroundColor(argb);
}
/**
* Returns the path of the canvas background image.
*
* @return the path of the canvas background image
*/
@SimpleProperty(
description = "The name of a file containing the background image for the canvas",
category = PropertyCategory.APPEARANCE)
i got reference from source code of canvas
Can you show your imports?
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.util.YailList;
import android.view.View;
import android.graphics.Color;
amazing it work now sorry it is my net issue
1 Like
wait there is another issue
the code
@SimpleFunction(description = "")
public void bgset(AndroidViewComponent component,YailList colors) {
View view = component.getView();
int index1 = 0;
for(Object x : colors ) {
view.setBackgroundColor((int)x);
index1++;
}
}
blocks
result
error-gnu.mapping.SimpleSymbol cannot be cast to java.lang.Integer
my last color in list is green so it should be green
i know that the object is related to error
Use this:-
@SimpleFunction(description = "")
public void bgset(AndroidViewComponent component, List<Integer> colors){
String listString = colors.toString();
View view = component.getView();
final String[] array = listString.split(" ");
final int[] ints = new int[array.length];
for (int i = 0; i < array.length; ++i) {
try {
ints[i] = Integer.parseInt(array[i]);
}
catch (NumberFormatException ex) {}
}
view.setBackgroundColor(ints);
}
What are you trying to do??
/appinventor/components/src/in/hifi/Bgcolour/Bgcolour.java:49: error: incompatible types: int[] cannot be converted to int
[javac] view.setBackgroundColor(ints);
setBackgroundColor
accepts int but you are giving int array here.
1 Like
This is just a learn,test extension I will use it in my main extension
Ken
February 11, 2021, 6:24am
14
You can achieve:
By adding this import:
import gnu.math.IntNum;
And using this code:
@SimpleFunction (description = "")
public void bgset(AndroidViewComponent component,YailList colors) {
View view = component.getView();
Object[] array = colors.toArray();
for(Object x : array) {
IntNum colorX = (IntNum)x;
view.setBackgroundColor(colorX.intValue())
}
}
5 Likes
@Ken does that method adds color to the old background color?
Because if it accepts only one value then background color should be the last value of list.
1 Like
Ya that's what I need because i have used this as a doubt part of my another extension this I not major extension
Ken
February 11, 2021, 1:02pm
18
As you suspected, it doesn't add to the background color, it replaces the color.
The end result of this particular method isn't important, it was only to show how you could iterate through a list of colors.
3 Likes
Taifun
February 11, 2021, 2:47pm
19
quick reminder concerning the naming conventions...
If you are developing an extension, then please follow the naming conventions, which is UpperCamelCase for the package name as well as for property, method and event names (i.e. the first letter should be a capital letter) and lowerCamelCase for parameter names, no underscores .
Example
[naming]
What does UpperCamelCase mean?
UpperCamelCase (part of CamelCase ) is a naming convention in which a name is formed of multiple words that are joined together as a single word with the first lā¦
Taifun
Trying to push the limits! Snippets , Tutorials and Extensions from Pura Vida Apps by Taifun.
3 Likes
system
Closed
February 18, 2021, 2:48pm
20
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.