Android Question Index Vs Array on Android 4.1.2

Saverio

Member
Licensed User
Longtime User
Hello to everybody,
this is Saverio, it's my first time here.

Attached there is an extract of a project perfectly working on the emulator (Android 4.4.2 Api_19)
but not properly working neither on real device (Galaxy Note2 4.1.2) nor on emulator (Android 4.1.2 API_16).

In the example there are two button both with StateListDrawable populated with GradientDrawable.

For the first button, the gradients color buffer is filled by index (Clr(0)=SomeColor), instead, in the
second one, the same thing, it's done by array (Clr=Array as int(SomeColor1, SomeColor2).

The Problem is that, for the first button, I got the same color, even pressed or released.
As you can see, from the example, I also tried Colors.ARGB, but got same result.

The question is, there is some good boy that can explain this

Ciao to everyone

Note2 4.1.2 Emu 4.1.2 Emu 4.4.2
Note2 4.1.2.png Emu 4.1.2.png Emu 4.4.2.png
 

Attachments

  • Index_Vs_Array.zip
    6 KB · Views: 142

Saverio

Member
Licensed User
Longtime User
Thank you for reply.

But the question remain.

Why it behave in different way among Api-19 and Api-16?
It's, Android or Basic4Android, problem?
It is just to know which method it's better to use when work with StateListDrawable.

Erel or someone else can explain that?

Saverio
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are reusing the same array multiple times.
This means that when you change the color of clr(0) you affect the previous drawables as well.

Add:
B4X:
Dim clr(2) As Int
Before you set the values. This will create a new array and will not affect the previous drawables.

Whether the change has an effect or not depends on the internal implementation of the views and drawables.
 
Upvote 0

Saverio

Member
Licensed User
Longtime User
I agree, at all, with you.

But, anyway, as I said in the reply #3, the question remain
"Why it behave in different way among Api-19 and Api-16?"

Saverio
 
Upvote 0

Saverio

Member
Licensed User
Longtime User
So, finally, it's better to use a buffer for each GradientDrawable.
My thought was to save ram.
I guess it's better lose some byte rather than compatibility.

Thanks Erel

Saverio
 
Upvote 0

Saverio

Member
Licensed User
Longtime User
Oh! I know that.

It's just my ancient mania.

When I was a "bit" younger, my favorite games were tasm4, turbodebugger4 and quickc2.5.
When there was something impossible to do, in those days, you could use, inside a "C" function, "_asm",
and take control of everything.
Of course "everything" it became programmer's responsibility. It was like old western movie duel.
I'm getting romantic.

Anyway, I have another question about OnTouch event.
Time to do some test, and I will start another thread.
 
Upvote 0
Top