F forisco70 Member May 8, 2024 #1 Hi to all! With this code i obtain an error: B4X: Private Sub clickDate_Click Dim btnDate As ImageView = Sender Dim edtText As EditText = btnDate.Tag selectionDate(edtText) 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!
Hi to all! With this code i obtain an error: B4X: Private Sub clickDate_Click Dim btnDate As ImageView = Sender Dim edtText As EditText = btnDate.Tag selectionDate(edtText) 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!
Solution Erel May 10, 2024 Better to use a Map: Code: Private edts As Map = CreateMap("1": edt1, "2": edt2, "3": edt3) 'And later edts.Get(btnData.Tag).As(B4XView).Text = myDate
Better to use a Map: Code: Private edts As Map = CreateMap("1": edt1, "2": edt2, "3": edt3) 'And later edts.Get(btnData.Tag).As(B4XView).Text = myDate
drgottjr Expert Licensed User Longtime User May 9, 2024 #2 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: [CODE lang="b4x"] Dim edtText As EditText = btnDate.Tag [/CODE] 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
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: [CODE lang="b4x"] Dim edtText As EditText = btnDate.Tag [/CODE] 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.
F forisco70 Member May 9, 2024 #4 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: B4X: 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
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: B4X: 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!!!
Erel B4X founder Staff member Licensed User Longtime User May 10, 2024 #5 Better to use a Map: Code: Private edts As Map = CreateMap("1": edt1, "2": edt2, "3": edt3) 'And later edts.Get(btnData.Tag).As(B4XView).Text = myDate Upvote 0 Solution
Better to use a Map: Code: Private edts As Map = CreateMap("1": edt1, "2": edt2, "3": edt3) 'And later edts.Get(btnData.Tag).As(B4XView).Text = myDate