Android Question Class: FocusChanged event fires only when the class ends

demasi

Active Member
Licensed User
Longtime User
Hello,
I need to change the background color of the edittext that has focus in a class.
The edittext event TextChange fires normally.
But the FocusChanged event fires only when the class ends.
The class is called by a button in Main activity to get the activity context.
Why the FocusChanged events are delayed?
Is there a way to change the background of the edittexts in my class when the focus change?
Thank you.

B4X:
Sub Class_Globals
    Dim edt,edt2 As EditText
    Dim cd As CustomDialog   
    Dim pnl As Panel
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub

Sub Show
    Dim ret As Int 
    edt.Initialize("edt")
    edt2.Initialize("edt")
    edt.TextColor=Colors.Black
    edt.Color = Colors.LightGray
    edt2.TextColor=Colors.Black
    edt2.Color = Colors.LightGray
    pnl.Initialize("")
    pnl.AddView(edt, 1%x, 0%y, 90%x, 50dip)
    pnl.AddView(edt2, 1%x, 60dip, 90%x, 50dip)
    cd.AddView(pnl,0,0,100%x,30%Y)
    ret = cd.Show("Event Test", "OK", "Cancel", "", Null)       
    Return ret 
End Sub

Sub edt_EnterPressed
    ToastMessageShow("enter",False)
End Sub

Sub edt_FocusChanged (HasFocus As Boolean)
    ToastMessageShow("focus",False)
    Dim wedt As EditText
    wedt = Sender
    wedt.Color = Colors.ARGB(255,Rnd(0,256),Rnd(0,256),Rnd(0,256))
End Sub

Sub edt_TextChanged (Old As String, New As String)
    ToastMessageShow("changed",False)
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
You did not call the sub show. So what did you expect to be done by magic hands?
 
Upvote 0

demasi

Active Member
Licensed User
Longtime User
Sorry. I forgot to send the project. There´s a Main activity with a button to call the Show method.
This is the project.
Thank you for your prompt answer.
 

Attachments

  • Project.zip
    7.5 KB · Views: 263
Upvote 0

demasi

Active Member
Licensed User
Longtime User
Thank you Erel.
But why the TextChanged event is fired and the FocusChanged is not? They have different processing?
 
Upvote 0
Top