Android Question XUI Dialog and StateListDrawable buttons

wimpie3

Well-Known Member
Licensed User
Longtime User
A possible bug (or perhaps it's me overlooking something...)

I'm creating a state list:
B4X:
    Dim DefaultDrawable, PressedDrawable As ColorDrawable
    DefaultDrawable.Initialize(Colors.Green,55dip)
    PressedDrawable.Initialize(Colors.Red,55dip)
    Dim sld As StateListDrawable
    sld.Initialize
    sld.AddState(sld.State_Pressed, PressedDrawable)
    sld.AddCatchAllState(DefaultDrawable)

Afterwards, I'm showing a dialog box:
B4X:
    Dim rs As ResumableSub = Dialog.ShowCustom(contentsPanel, "Ok", "Abort", "Cancel")

Now I want to apply the StateList to the three buttons:
B4X:
    Dim b As Button=Dialog.GetButton(xui.DialogResponse_Positive)
    b.Background=sld
    b=Dialog.GetButton(xui.DialogResponse_Negative)
    b.Background=sld
    b=Dialog.GetButton(xui.DialogResponse_Cancel)
    b.Background=sld

What happens now is that when I click the first button, the color of the third button is changed as well. When I click the second button, the third button changes also.
 

stevel05

Expert
Licensed User
Longtime User
Without trying it I would guess that you need a different instance of the statelist for each button.
 
Upvote 1
Solution

wimpie3

Well-Known Member
Licensed User
Longtime User
Ah, I didn't know statelists weren't re-usable. Will give that a try.

EDIT: you're right, three buttons need three different statelists... but WHY?
 
Last edited:
Upvote 0
Top