Hi
how delete dynamically added panel
have 2 button 1 for add new panel & 1 for remove panel with its contain data
we add panel dynamically, each panel has one delete check box to select and delete with button
here i attached my code and project folder
how delete dynamically added panel
have 2 button 1 for add new panel & 1 for remove panel with its contain data
we add panel dynamically, each panel has one delete check box to select and delete with button
here i attached my code and project folder
B4X:
Private Sub add_button_Click
FrameCounter = FrameCounter + 1 ' Increment the frame counter
Dim NewPanel As B4XView = xui.CreatePanel("")
NewPanel.Color = xui.Color_ARGB(255, 224, 224, 235) ' Set a background color for the frame
MainScroll.Panel.AddView(NewPanel, 15dip, 100dip + (FrameCounter - 1) * 150dip, 92%x, 140dip) ' Dynamically position each frame
Dim Newlable As Label
Dim DLY_lable As Label
' Add checkboxes dynamically
Dim i As Int
Dim chkList As List
chkList.Initialize
For i = 0 To 6
Dim chk As CheckBox
chk.Initialize("chk_" & FrameCounter & "_" & i) ' Unique ID for each checkbox
chk.Text = i
chk.Tag = FrameCounter & "_" & i ' Store panel and checkbox index
NewPanel.AddView(chk, 10dip + (i * 60dip), 20dip, 100dip, 20dip) '// horizontal
chk.Tag = i & "_" & FrameCounter
chkList.Add(chk)
Next
Newlable.Initialize("")
Newlable.Color = xui.Color_ARGB(255, 224, 224, 235)
Newlable.TextColor = Colors.red
Newlable.TextSize = 20
NewPanel.AddView(Newlable, 10dip, 50dip, 70%x, 40dip) ' Position inside the panel
Newlable.Text = "Time 12 : 30"
DLY_lable.Initialize("")
'Newlable.Color = Colors.White
DLY_lable.Color = xui.Color_ARGB(255, 224, 224, 235)
DLY_lable.TextColor = Colors.red
DLY_lable.TextSize = 20
NewPanel.AddView(DLY_lable, 10dip, 100dip, 70%x, 40dip) ' Position inside the panel
DLY_lable.Text = "Cycle On: 10 S - 20 S"
' Create a Button inside the frame
Dim NewButton As Button
NewButton.Initialize("DynamicButton") ' Set event name for click events
NewButton.Text ="Edit"
NewPanel.AddView(NewButton, 360dip, 90dip, 15%x, 40dip)
' Add checkbox
Dim chk As CheckBox
chk.Initialize("")
chk.Tag = "DEL_" & NewPanel.Tag ' Store panel tag for reference
chk.Text = "DEL"
NewPanel.AddView(chk, 280dip, 90dip, 15%x, 40dip)
' Attach the Frame ID to the button's Tag for identification
NewButton.Tag = FrameCounter
' Store the panel and its checkboxes
panelList.Add(Array As Object(NewPanel, 0, panelList.Size + 1))
MainScroll.Panel.Height = Max(MainScroll.Height, 10dip + FrameCounter * 150dip)
End Sub
Private Sub del_Button_Click
Dim toRemove As List
toRemove.Initialize
Dim panelData() As Object = panelList.Get(0)
Dim pnl As B4XView = panelData(0)
Log(pnl)
' For Each pnl As B4XView In panelList
' Dim chk As CheckBox = pnl.GetView(0) ' First view is checkbox
' Dim i As B4XView = pnl.GetView(0) ' First view is checkbox
' Log(i.Text)
'If chk.Checked Then
' toRemove.Add(pnl)
'End If
' Next
' Remove panels
' For Each pnl As B4XView In toRemove
'pnlContainer.RemoveView(pnl)
'panelList.Remove(pnl)
' pnlContainer.RemoveViewFromParent
' panelList.RemoveAt(pnl)
' Next
End Sub