Hi,
I am using a custom list view that presents labels and push buttons. The labels are filled from a database.
I wish to change the data for a specific item in the list and have it updated.
Code to set a label in an item
I have tried to do this by changing the label text, but even though I jump to the item in the list I wish to change, it is the last record in the list that gets changed not the one I have jumped to.
How can this be done. Is there a simple way or do I have to delete the item I wish to change, make a new one and insert the new item in the old ones place?
Best regards
Rob.
I am using a custom list view that presents labels and push buttons. The labels are filled from a database.
I wish to change the data for a specific item in the list and have it updated.
List Builder:
'======================================================================================================
Sub CreateListItem(Width As Int, Height As Int, row() As Object) As Panel
Dim p As Panel
p.Initialize("")
p.SetLayout(0, 0, Width, Height) 'set the panel size before you load the layout.
'The above line will fail on B4A < v7.30. You should instead add the panel to the Activity with Activity.AddView and remove
'it after calling LoadLayout with p.RemoveView.
p.LoadLayout("logCell")
btnStart.Tag = 0
Dim titleStr As String = row(0) & " - " & row(2)
titleStr = titleStr.Trim
lblExDesc.Text = titleStr
lblStartTime.Text = " - "
lblStartTime.TextColor = 0xFF000000
lblEndTime.Text = " - "
lblEndTime.TextColor = 0xFF000000
lblTargetWeight.Text = row(3) & " kg"
lblTargetReps.Text = "Rps " & row(4)
lblTargetLifts.Text = "Sets " & row(5)
lblNewWeight.Text = lblTargetWeight.Text
lblNewLifts.Text = lblTargetLifts.Text
lblNewReps.Text = lblTargetReps.Text
Return p
End Sub
'======================================================================================================
Public Sub setcvLogList(tabNo As Int)
Dim cursor As Int
Dim pcv As Panel
Dim exerciseList As List = dbRT.getExerciseListByWGRec(tabNo + 1)
setTableExRecsFromDb(exerciseList, 1)
'Clear the custom view list
If cvLogList.GetSize > 0 Then
cvLogList.Clear
End If
cursor = 1
For Each row() As Object In exerciseList
pcv = CreateListItem(cvLogList.AsView.Width, 90dip, row)
cvLogList.Add(pcv, 90dip, 1)
cursor = cursor + 1
Next
cvLogList.JumpToItem(0)
End Sub
Code to set a label in an item
B4X:
'======================================================================================================
Sub whlWeight_tick
tableLogDirtyFlag = True
If tblLogDirty.weightKg = False Then
tblLogUpdate.weightKg = tblLog.weightKg
End If
tblLogDirty.weightKg = updateFromWheel(whlWeight, lblNewWeight, lblTargetWeight, 1, "", "")
ToolBar.Menu.FindItem(20).Visible = Not(logDirtyCheck)
End Sub
'======================================================================================================
Sub updateFromWheel(whl As WheelView, fieldToUpdate As Label, labelToCompare As Label, valuePos As Int, Prefix As String, Suffix As String) As Boolean
'Put the selected weight in the New Weight Field and database mem record
Dim whlStr As String
Dim whlStrNum As String
Dim lblCompStr As String
Dim sf As StringFunctions2
sf.Initialize
whlStr = whl.ReadWheel
lblCompStr = sf.SplitGetWord(labelToCompare.Text, " ", 0)
lblCompStr = lblCompStr.Trim
whlStrNum = sf.SplitGetWord(whlStr, " ", valuePos)
whlStrNum = whlStrNum.Trim
If Prefix = "" And Suffix = "" Then
fieldToUpdate.Text = whlStrNum & " " & sf.SplitGetWord(whlStr, " ", 2)
Else
fieldToUpdate.Text = Prefix & " " & whlStrNum & " " & Suffix
End If
If lblCompStr.CompareTo(whlStrNum) = 0 Then
fieldToUpdate.TextColor = 0xFF000000
Return False
Else
fieldToUpdate.TextColor = 0xFFFF0000
Return True
End If
End Sub
I have tried to do this by changing the label text, but even though I jump to the item in the list I wish to change, it is the last record in the list that gets changed not the one I have jumped to.
How can this be done. Is there a simple way or do I have to delete the item I wish to change, make a new one and insert the new item in the old ones place?
Best regards
Rob.