ThePuiu Active Member Licensed User Longtime User Dec 2, 2019 #1 I have an interface consisting of a Save button and a Custom List. The list contains a variable number of items. Each item contains the same controls (loaded from a layout): few B4XPlusMinus, one B4XSwitch and an EditText. When I click on the Save button, want to read all the values from all the items in the list and save them in a database. I was thinking about setting the Tag property identical to the value of the object when opening the interface. This way I can check if the value of the object is different at the time of saving and send to the server only those that have changed. I ran into a problem: I do not know how to determine when I click the Save button the objects that interest me. The solution found (clearing all the Views in the panel and reading only those that matter) uses precisely the Tag property to identify the object ... Another idea would be to save in the Tag property of a Map type structure that contains both the object identifier and the initial value. This approach seems to slow down the application even more... What do you recommend?
I have an interface consisting of a Save button and a Custom List. The list contains a variable number of items. Each item contains the same controls (loaded from a layout): few B4XPlusMinus, one B4XSwitch and an EditText. When I click on the Save button, want to read all the values from all the items in the list and save them in a database. I was thinking about setting the Tag property identical to the value of the object when opening the interface. This way I can check if the value of the object is different at the time of saving and send to the server only those that have changed. I ran into a problem: I do not know how to determine when I click the Save button the objects that interest me. The solution found (clearing all the Views in the panel and reading only those that matter) uses precisely the Tag property to identify the object ... Another idea would be to save in the Tag property of a Map type structure that contains both the object identifier and the initial value. This approach seems to slow down the application even more... What do you recommend?
ThePuiu Active Member Licensed User Longtime User Dec 2, 2019 #2 This code snippet seem to work ... but i have more than one object with Tag as B4XPlusMinus... Code: For Each v As B4XView In p.GetAllViewsRecursive If v.Tag Is B4XPlusMinusThen Dim btn As B4XPlusMinus = v.Tag ToastMessageShow("Buton " & i & " :" &btn.SelectedValue, True) End If Next Last edited: Dec 2, 2019 Upvote 0
This code snippet seem to work ... but i have more than one object with Tag as B4XPlusMinus... Code: For Each v As B4XView In p.GetAllViewsRecursive If v.Tag Is B4XPlusMinusThen Dim btn As B4XPlusMinus = v.Tag ToastMessageShow("Buton " & i & " :" &btn.SelectedValue, True) End If Next
ThePuiu Active Member Licensed User Longtime User Dec 2, 2019 #3 try to do that for an EditText that have the Tag properties = B4XView : Code: If v.Tag Is B4XView Then Dim tag As String = v.Tag If tag.Length > 0 Then Dim btne As EditText = v.Tag sDen = btne.Text.Trim End If End If but get an error: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView Upvote 0
try to do that for an EditText that have the Tag properties = B4XView : Code: If v.Tag Is B4XView Then Dim tag As String = v.Tag If tag.Length > 0 Then Dim btne As EditText = v.Tag sDen = btne.Text.Trim End If End If but get an error: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
LucasHeer Active Member Licensed User Longtime User Dec 2, 2019 #4 Just a recommendation, but If you had a Type that defined each of your list objects, that would help you tremendously. Then you could have an array or list prebuilt, and not rely on the list view itself. In this type you could have: Code: Type listObject (id As Int, value As Int) If you wanted a list or array: Code: Public listObjects As List Public listObjects() As listObject You can set the tag of the listview panel OR the B4XPlusMinus to the ID/Index of your value, then just modify that index/ID whenever the click/valueChanged event occurs. You can access the ID/Index inside of the CLV_click or B4XPlusMinus function: Code: Dim myPanel As Panel = Sender Dim myID As Int = myPanel.tag Once you click the save button, you can map your array/list, and use the JSONGenerator to store a string in your Database. When you go to read from the database, just decode the string. Upvote 0
Just a recommendation, but If you had a Type that defined each of your list objects, that would help you tremendously. Then you could have an array or list prebuilt, and not rely on the list view itself. In this type you could have: Code: Type listObject (id As Int, value As Int) If you wanted a list or array: Code: Public listObjects As List Public listObjects() As listObject You can set the tag of the listview panel OR the B4XPlusMinus to the ID/Index of your value, then just modify that index/ID whenever the click/valueChanged event occurs. You can access the ID/Index inside of the CLV_click or B4XPlusMinus function: Code: Dim myPanel As Panel = Sender Dim myID As Int = myPanel.tag Once you click the save button, you can map your array/list, and use the JSONGenerator to store a string in your Database. When you go to read from the database, just decode the string.