I have made this code, to put a JSON file into a ScrollView
But when I run it I got the next error:
The Specified child already has a parent. You must call removeView on the child's parent first.
What did I do wrong ?
B4X:
Dim JSON As JSONParser
Dim m, Map1 As Map
Dim Title As String
Dim MenuItems As List
Dim lblTitle As Label
Dim lblItem As Label
iTel = 0
lblTitle.Initialize("")
lblItem.Initialize("")
ScrollView1.Panel.Height=2dip * ScrollView1.Height
ScrollView1.Panel.Color = Colors.Transparent
Map1.Initialize()
JSON.Initialize(File.ReadString(File.DirAssets, "nieuwsapp.json"))
Map1 = JSON.NextObject
MenuItems = Map1.Get("newsitems")
'MenuItems = m.Get("newsitem")
For i = 0 To MenuItems.Size - 1
m = MenuItems.Get(i)
m = m.Get("newsitem")
Title = m.Get("title")
Content = m.Get("content")
lblTitle.Text = Title
lblItem.Text = Content
lblTitle.TextColor = Colors.Black
lblTitle.TextSize = 12
lblItem.TextColor = Colors.Black
lblItem.TextSize = 10
ToastMessageShow(iTel & " " & Title,True)
ScrollView1.Panel.AddView(lblTitle, 5dip, 5dip + iTel * 120dip, ScrollView1.Width, 150dip)
'ScrollView1.Panel.AddView(lblItem, 5dip, 40dip + iTel * 120dip, ScrollView1.Width, 150dip)
iTel=iTel+1
'Log(m.Get("title"))
Next
But when I run it I got the next error:
The Specified child already has a parent. You must call removeView on the child's parent first.
What did I do wrong ?