Android Question Dynamically Add and Update Panels

Mitesh_Shah

Member
Licensed User
Longtime User
Hi
on add button click will add dynamically, panel, 2 integer variables, and one edit button
on edit button want to change/edit/update variable value

want to know how change / update both variable

B4X:
' Add a new panel dynamically
Private Sub btnAddPanel_Click(View As Object)
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, panelList.Size * 110dip, pnlMain.Width, 100dip)
    pnl.Color = xui.Color_LightGray
    pnlMain.AddView(pnl)

    ' Label to display integer
    Dim lbl As B4XView = xui.CreateLabel("")
    lbl.SetLayoutAnimated(0, 10dip, 20dip, pnl.Width - 20dip, 50dip)
    dim int_val1 as int
       
    lbl.Text = int_val1
    lbl.TextSize = 20
    lbl.SetTextAlignment("CENTER", "CENTER")
    pnl.AddView(lbl)

    ' Store panel and integer value
    panelList.Add(Array As Object(pnl, int_val1, panelList.Size + 1))
End Sub


' Update the last added panel's integer value
Private Sub btnUpdatePanel_Click(View As Object)
    If panelList.Size = 0 Then
        Log("No panels available to update")
        Return
    End If

    ' Select last added panel
    selectedPanelIndex = panelList.Size - 1
    Dim panelData() As Object = panelList.Get(selectedPanelIndex)
    Dim lbl As B4XView = panelData(1)
    Dim intValue As Int = 25

    ' Update label text
    lbl.Text = intValue
    panelList.Set(selectedPanelIndex, Array As Object(panelData(0), lbl, intValue))

    Log("Updated Panel " & (selectedPanelIndex + 1) & " to Value: " & intValue)
End Sub

after update lbl.text not change
its possible to after update lbl.text can referees
 
Last edited:

emexes

Expert
Licensed User
If is only one set of added views, then would be simpler to include them on the layout, default disabled, and have the button click enable them (or perhaps, toggle them on and off? and perhaps reset them to default values when enabling them).
 
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
Hi Here i attached Full Projects in Zip and Screen Shots
 

Attachments

  • screen shot.jpg
    screen shot.jpg
    429.4 KB · Views: 58
  • B4A_TEST.zip
    5.8 KB · Views: 36
Upvote 0

aeric

Expert
Licensed User
Longtime User
I suggest you use CustomListview.
Check my example here:
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The project you posted does not work !
It seems that it is a B4XPages project and i get the message that the B4XMainPage module is missing.
To zip a B4XPages project you must click on this line on top of the B4XMainPage module.
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=CameraIntent.zip
 
Upvote 0

emexes

Expert
Licensed User
Here's one way of maybe doing something like what you're looking for:

1739870538626.png
1739870553110.png

1739870568781.png
1739870581878.png



B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private Button2 As Button
    Private Panel1 As Panel
    Private CheckBox1 As CheckBox
    Private Label1 As Label
    Private Spinner1 As Spinner
    Private Spinner2 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
   
    CheckBox1.Checked = False
    UpdateFromCheckbox(CheckBox1.Checked)
   
    Spinner1.Clear
    Spinner2.Clear
    Spinner1.AddAll((Array As Int(1, 2, 3, 4, 5, 6)).As(List))
    Spinner2.AddAll((Array As Int(2, 3, 5, 7, 11, 13, 17, 19)).As(List))
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button1_Click
    '''xui.MsgboxAsync("Hello world!", "B4X")
End Sub

Private Sub Button2_Click
    Spinner1.Enabled = True
    Spinner2.Enabled = True
End Sub

Private Sub CheckBox1_CheckedChange(Checked As Boolean)
    UpdateFromCheckbox(Checked)
    If Checked Then
        Spinner1.Enabled = False
        Spinner2.Enabled = False
    End If
End Sub

Sub UpdateFromCheckbox(Checked As Boolean)
    Panel1.Enabled = Checked
    Panel1.Visible = Checked
       
    If Checked Then
        Label1.Text = "Untick to remove shipping"
    Else
        Label1.Text = "Tick to add shipping"
    End If
End Sub
 
Last edited:
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
Hi emexes, Thank's For Reply

We make Multi events timer App, so its Required multiple event data, like on_time, Off_Time and calendar Day Selection. here we attached some screen shots

its possible refresh the dynamically added panel and its data, Like textbox or variables ?


 

Attachments

  • Timer_App_2.jpg
    Timer_App_2.jpg
    33.8 KB · Views: 41
  • Timer_App_3.jpg
    Timer_App_3.jpg
    33.5 KB · Views: 35
  • Timer_App_4.jpg
    Timer_App_4.jpg
    34.4 KB · Views: 36
  • Timer_App_5.jpg
    Timer_App_5.jpg
    39.4 KB · Views: 39
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
Hi
Here some screen shots of our projects

on add button click we add dynamic panel and some timer data,
on edit button click we open b4x dialog box and edit the panel data
 

Attachments

  • sch1.jpg
    sch1.jpg
    167.7 KB · Views: 29
  • sch3.jpg
    sch3.jpg
    92.1 KB · Views: 28
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached a modified version of your project.
I changed the DynamicButton_Click routine with a different approach to get the different values.
I modified the top and height properties of the MainScroll which was also behind the two top Buttons.
I changed the position of the Dynamic buttons which were not visible on the panels.
 

Attachments

  • B4XDialogNew.zip
    13.7 KB · Views: 29
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
Attached a modified version of your project.
I changed the DynamicButton_Click routine with a different approach to get the different values.
I modified the top and height properties of the MainScroll which was also behind the two top Buttons.
I changed the position of the Dynamic buttons which were not visible on the panels.
OH ! Excellent
Thank's,
 
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
Attached a modified version of your project.
I changed the DynamicButton_Click routine with a different approach to get the different values.
I modified the top and height properties of the MainScroll which was also behind the two top Buttons.
I changed the position of the Dynamic buttons which were not visible on the panels.
Hi
thank, ur example is work perfectly

want some more info about ,
lbl1 = parentPanel.GetView(0) 'gets the Label from the Panel
lbl2 = parentPanel.GetView(1) 'gets the Label from the Panel

how to use in dialog box, will try but get some Error >> only Length is supported by Arrays
 
Upvote 0
Top