Android Question Java to B4A Translation

Shadow&Max

Active Member
Licensed User
Hi...

I found this snippit of Java code, but I can't figure out how to translate it into B4A. Any help would be appreciated. Is this even possible?

B4X:
protected void setMarqueeSpeed(TextView tv, float speed, boolean speedIsMultiplier) {

    try {
        Field f = tv.getClass().getDeclaredField("mMarquee");
        f.setAccessible(true);

        Object marquee = f.get(tv);
        if (marquee != null) {

            String scrollSpeedFieldName = "mScrollUnit";
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.L)
                scrollSpeedFieldName = "mPixelsPerSecond";

            Field mf = marquee.getClass().getDeclaredField(scrollSpeedFieldName);
            mf.setAccessible(true);

            float newSpeed = speed;
            if (speedIsMultiplier)
                newSpeed = mf.getFloat(marquee) * speed;

            mf.setFloat(marquee, newSpeed);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
This I think would solve a big problem for me now.

Thanks in advance...
 

Shadow&Max

Active Member
Licensed User
It should be quite simple to implement it with the Reflection library.

This will help you get started:
B4X:
Dim r As Reflector
r.Target = tv
Dim marquee As Object = r.GetField("mMarquee")
Thanks Erel... I'll give it a try. Much appreciated...
 
Top