Android Question Problem with "SetNinePatchButton"

Discussion in 'Android Questions' started by Filippo, Apr 12, 2019.

  1. Filippo

    Filippo Expert Licensed User

    Hi,

    in Crashlytics always comes back this crash report:
    The crash always happens at the procedure:
    Code:
    Private Sub SetNinePatchButton(Btn As Button, DefaultImage As String, PressedImage As String)
        
    Dim r As Reflector
        
    Dim package As String
        
    Dim idDefault, idPressed As Int
        package = r.GetStaticField(
    "anywheresoftware.b4a.BA""packageName")
        idDefault = r.GetStaticField(package & 
    ".R$drawable", DefaultImage)
        idPressed = r.GetStaticField(package & 
    ".R$drawable", PressedImage)
        r.Target = r.GetContext
        r.Target = r.RunMethod(
    "getResources")
        
    Dim sd As StateListDrawable
        sd.Initialize
        sd.AddState(sd.State_Pressed, r.RunMethod2(
    "getDrawable", idPressed, "java.lang.int"))
        sd.AddCatchAllState( r.RunMethod2(
    "getDrawable", idDefault, "java.lang.int"))
        Btn.Background = sd
    End Sub
    Of course all resources are available under ".. \ Objects \ res \ drawable".

    As always, the crash does not happen with all devices, so it is difficult to make the mistake reproducible.
    My question is now: can one change this procedure so that one no longer uses the library "Reflector"?
     
    Last edited: Apr 12, 2019
  2. DonManfred

    DonManfred Expert Licensed User

    this is the english part of the forum. Please write english here.
     
  3. Filippo

    Filippo Expert Licensed User

    It's all in English, or not? :p
     
  4. DonManfred

    DonManfred Expert Licensed User

    not really :D
    :p:p:p
     
  5. Filippo

    Filippo Expert Licensed User

    That is not true!
    Do not you have any glasses on? :D

    But fun side by side, do you perhaps know another solution to this problem?
     
  6. DonManfred

    DonManfred Expert Licensed User

    Sure i have! If i would not then it is nearly impossible to read anything on the monitor :D or better :(
     
    Filippo likes this.
  7. DonManfred

    DonManfred Expert Licensed User

    sorry, no.
     
  8. agraham

    agraham Expert Licensed User

    This is a guess, but from the error it would seem to be related to the density of the display which would explain why it doesn't work on some devices. It looks like some density related resource is missing - but there my ignorance starts (and ends!) I'm afraid :(
     
    Filippo likes this.
  9. Filippo

    Filippo Expert Licensed User

    Thank you very much agraham. :)
    I hope now that Erel knows something more, otherwise I have to think of something else.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    You can use XmlLayoutBuilder instead of the reflection based code (which is fine as well).

    I guess that you aren't able to reproduce this error, right?

    Is there anything special with the resource files? Maybe they are too large?
     
  11. Filippo

    Filippo Expert Licensed User

    Yes, that's always the problem.

    I do not think it's special, it's just these 2 files attached.
     

    Attached Files:

  12. Filippo

    Filippo Expert Licensed User

    I have now found another solution without having to use the function "SetNinePatchButton".
    I think my keyboard looks even better now without bitmaps. :)

    upload_2019-4-14_16-26-6.png
     
    XbNnX_507 and Erel like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice