Android Question Cast a string to EditText


Hi to all! With this code i obtain an error:

Private Sub clickDate_Click
    Dim btnDate As ImageView = Sender
    Dim edtText As EditText = btnDate.Tag
End Sub

Private Sub selectionDate (dateField As  EditText)
    dateField.Text = DateTime.Date(DateTime.Now)

End Sub

What's the right way to pass a string as a valid EditText? Thanks!
Better to use a Map:
Private edts As Map = CreateMap("1": edt1, "2": edt2, "3": edt3)
'And later
edts.Get(btnData.Tag).As(B4XView).Text = myDate


Licensed User
Longtime User
there is no way - right or wrong. i'm guessing that's exactly what you saw when you tried to run your project

btnDate.Tag is an object. as such it can be a string (if you like) or an edittext. technically, there is nothing wrong with:
    Dim edtText As EditText = btnDate.Tag
assuming Sender's tag is an edittext. in this case, somewhere up the line of your crisscross code there is an imageview. set its tag to an edittext. if you set a view's tag to a string, then it can't be cast as a view.
Upvote 0


Thanks to both of you, friends! In the designer mode, i don't know how to set the tag property of an imageview to an edittext! Anyway, i solved in this way: i set up tags of the imageviews as 1, 2, 3, ... and then i wrote this code in the clickDate event:
Dim btnData As ImageView = Sender, indice As Int = btnData.Tag
    ' something for mydate'
        Select indice
            Case 1
                edt1.Text = myDate
            Case 2
                edt2.Text = myDate
            Case 3
                edt3.Text = myDate
        End Select
    End If
For now, all works fine! Bye!!!
Upvote 0