Android Question AddHandleActionEvent with Label

Declan

Well-Known Member
Licensed User
Longtime User
I have a simple app that creates a CustomListView that contains 2 Labels.
When the lblEvent is clicked, I open the keypad.
I then want to use the "Done" key of the keypad to save any text entered into lblEvent.
However, I get the following error on compile:
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 345)
java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
at anywheresoftware.b4a.samples.customlistview.main._activity_create(main.java:345)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.samples.customlistview.main.afterFirstLayout(main.java:102)
at anywheresoftware.b4a.samples.customlistview.main.access$000(main.java:17)
at anywheresoftware.b4a.samples.customlistview.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText

My project code:
B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: CustomListView Example
    #VersionCode: 1
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    Private clv2 As CustomListView
    Dim IME As IME
    Private lblEvent As Label
    Private lblTime As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    IME.Initialize("IME")
    lblEvent.Initialize("lblEvent")
    IME.AddHandleActionEvent(lblEvent)
    For i = 1 To 10
        clv2.Add(CreateListItem($"Item #${i}"$, clv2.AsView.Width, 70dip), 70dip, $"Item #${i}"$)
    Next
   
End Sub

Sub IME_HandleAction As Boolean
   Dim e As EditText
   e = Sender
    Log("Text: " & e)
End Sub

Sub clv2_ItemClick(Index As Int, Value As Object)
    IME.ShowKeyboard(lblEvent)
    Log(Index & " = " & Value)
End Sub

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
    Activity.AddView(p, 0, 0, Width, Height)
    p.LoadLayout("CellItem")
    p.RemoveView
    'lblTime will point to the last added views.
    lblTime.Text = Text
    Return p
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Declan

Well-Known Member
Licensed User
Longtime User
Thanks, so I will replace the Label with a EditText.
Is it possible to remove the line in the EditText when it has focus?
Making the EditText look like a Label?
 
Upvote 0
Top