Android Question Sender does not work

Hello
I have defined several panels in the designer and have put edit text inside some of them.
Since the number of editing texts is very large, adding a large number of Sub, changing the focus and changing the text seems non-standard.
So, I plan to set the EventName of all of them the same and create only one sub and receive the text edits with the help of Sender.
But when the following code is executed, Null is printed or android.widget.Button{5c5198c VFED..C.. ...P..ID 118,1264-962,1411 #11}
B4X:
Private Sub MyEditText_FocusChanged (HasFocus As Boolean)
    Log(Sender)
End Sub
I also use B4xPages.
 
This should work (I didn't test it):

B4X:
Private Sub MyEditText_FocusChanged (HasFocus As Boolean)
    Dim et as EditText = Sender
    Log(et.Text)
End Sub
Thank you. This error occurred:
B4X:
Error occurred on line: 54 (B4XMainPage)
java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.EditText
    at b4a.example.test.b4xmainpage._edittext1_focuschanged(b4xmainpage.java:606)
    at b4a.example.test.b4xmainpage$ResumableSub_GoToPage.resume(b4xmainpage.java:436)
    at b4a.example.test.b4xmainpage._gotopage(b4xmainpage.java:86)
    at b4a.example.test.b4xmainpage._button1_click(b4xmainpage.java:491)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7506)
    at android.view.View.performClickInternal(View.java:7483)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:29334)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7872)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**
 
Upvote 0

Xfood

Expert
Licensed User
Thank you. This error occurred:
B4X:
Error occurred on line: 54 (B4XMainPage)
java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.EditText
    at b4a.example.test.b4xmainpage._edittext1_focuschanged(b4xmainpage.java:606)
    at b4a.example.test.b4xmainpage$ResumableSub_GoToPage.resume(b4xmainpage.java:436)
    at b4a.example.test.b4xmainpage._gotopage(b4xmainpage.java:86)
    at b4a.example.test.b4xmainpage._button1_click(b4xmainpage.java:491)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7506)
    at android.view.View.performClickInternal(View.java:7483)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:29334)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7872)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**

It looks like you've initialized a button as edittext

Dim et as EditText = Sender
java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.EditText ???
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Make sure you did not set your buttons event name to the same name as the text fields. Not impossible, but then you would have to check the type first, before proceeding to assign the sender to a variable of the appropriate type
 
Upvote 0
Top