0

I want to create in JavaScript a

new android.content.res.ColorStateList(states,colors)

which is defined as

public ColorStateList (int[][] states, int[] colors)

I cannot figure out how to pass the int[][] states parameter.


I've tried:

A.

var states = [
    [android.R.attr.state_pressed],
    [android.R.attr.state_enabled],
];

result:

Error: Cannot marshal JavaScript argument 16842919,16842910 at index 0 to Java type.

(16842919,16842910 are the two constants in the array.)

B.

var states = Array(2);
states[0] = Array.create("int",1);
states[0][0] = android.R.attr.state_pressed;
states[1] = Array.create("int",1);
states[1][0] = android.R.attr.state_enabled;

result:

Cannot marshal JavaScript argument [I@8033d59,[I@1e86d1e at index 0 to Java type.

2 Answers 2

2

Did you try to use Array.create()? In the documentation, it says "Occasionally you have to create Java arrays from JavaScript. For this scenario we added method create to built-in JavaScript Array object."

This sentence describes what you are trying to do IMO.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, after another hour of searching I found it, too. Thank you.
0

This worked:

var states = Array.create("[I",2);
states[0] = Array.create("int",1);
states[0][0] = android.R.attr.state_pressed;
states[1] = Array.create("int",1);
states[1][0] = android.R.attr.state_enabled;

More info here: Java to JavaScript Conversion: Array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.