Android Question array list question

tufanv

Expert
Licensed User
Longtime User
Hello,

I am trying to use a list in mpandoridcharts lib. My question is not about the library but arrays
If i set the chart data like this :

mlc1.Chart_High_Data = Array As Float(listhigh.Get(0),listhigh.Get(1)) ....

There is no problem chart loads succesffuly . But my data is huge so i cant add them one by one like list.get(0) , liste.get(1) ...

I have to load the complete list

but when i use
mlc1.Chart_High_Data = Array As Float(listhigh)

I get :

B4X:
java.lang.NumberFormatException: Invalid double: "(ArrayList) [2.84914, 2.8405, 2.8347, 2.81465, 2.8066, 2.85119, 2.9774, 2.9634, 2.94295, 2.94903, 2.95742, 2.9753, 2.96367, 2.97444, 2.9875, 2.977, 2.994, 3.00075, 2.9915, 2.99635, 3.01185, 2.9532, 2.94585, 2.96225, 2.9686, 2.9584, 2.95585, 2.95288, 2.9536, 2.9156, 2.91045, 2.9009, 2.90022, 2.93851, 2.9333, 2.94055, 2.9378, 2.95621, 2.9306, 2.9213]"

I get this error. Obviosuly i am using wrong code to load the whole list. Where is my mistake ?

Thanks
 

stevel05

Expert
Licensed User
Longtime User
I don't know that lib, but if Chart_High_Data is presenting a list you could try:

B4X:
mlc1.Chart_High_Data.addAll(listhigh)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
What type is it expecting?
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
What type is it expecting?
it says : As Float

as i said when i add one by one there is no problem but it is impossible to add more than 300 value by hand , problum occurs when i try to add whole list instead of list.get(0),list.get(1)....
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
What lib is it? A search for "mpandoridcharts" returns nothing.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Is it a float array?

You could try:
B4X:
    Dim LJO As JavaObject = listhigh
    mlc1.Chart_High_Data = LJO.RunMethod("toArray",Null)

If that doesn't work I'll download the library
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Is it a float array?

You could try:
B4X:
    Dim LJO As JavaObject = listhigh
    mlc1.Chart_High_Data = LJO.RunMethod("toArray",Null)

If that doesn't work I'll download the library
that gave me an error :

B4X:
java.lang.IllegalArgumentException: method mpandroidchartwrapper.candleStickChartWrapper.setChart_High_Data argument 1 has type float[], got java.lang.Object[]
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
OK you need to convert the list to a Float Array, it can be done with JavaObject:

B4X:
Dim LJO As JavaObject = listhigh
    Dim AJO As JavaObject
    AJO.InitializeArray("java.lang.Float",LJO.RunMethod("toArray",Null))
    mlc1.Chart_High_Data = AJO

Should work, but there is probably no benefit over doing it directly

B4X:
Dim Farray(listhigh.size) As Float
For i = 0 to listhigh.size - 1
  Farray(i) = listhigh.get(i)
Next
mlc1.Chart_High_Data = Farray
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
OK you need to convert the list to a Float Array, it can be done with JavaObject:

B4X:
Dim LJO As JavaObject = listhigh
    Dim AJO As JavaObject
    AJO.InitializeArray("java.lang.Float",LJO.RunMethod("toArray",Null))
    mlc1.Chart_High_Data = AJO

Should work, but there is probably no benefit over doing it directly

B4X:
Dim Farray(listhigh.size) As Float
For i = 0 to listhigh.size - 1
  Farray(i) = listhigh.get(i)
Next
mlc1.Chart_High_Data = Farray
thanks for your answers. first solution gives error :
B4X:
java.lang.IllegalArgumentException: Array has incompatible type: class [Ljava.lang.Float;

second one works perfect !
Thanks very much for the help and effort !
 
Upvote 0

Similar Threads

Top