I have been playing with this sample which uses XUI Views and a File called Example.JSON. I think I understand how to add additional content using the Example.JSON file, but it seems that I also need to create references to the additional lines in the JSON file somewhere else in the project. I then want to store the individual values relative to every item in the extended JSON file, so that I can test for them in the project.
Hope that's clear. I have attached the project as a ZIP, (without adding additional items in the JSON file (Found in the folder called Files)
The sample project is 3.6MB which wont upload as it is too large.
I have spent some hours on this problem, and rightly or wrongly I have come to the conclusion that I need to modify the Example.json File, PLUS dig into JAVA in some obscure files to complement the changes made in the JSON file. I have come to the secondary conclusion that this cannot possibly be true - The idea was to write code in B4X, not Java. I am starting to beIieve that the JAVA files are really a translation of what was originally programmed in B4X and are created automatically by the compiler. I really need to know how the concept of XUI Views works. I note that Klaus has a project displaying flowers, but this is not what I want to do.
H e l p P l e a s e
This sounds promising Erel ... If you don't understand what I am trying to say then clearly I am on the wrong track.
With the project there is a folder called FILES. Inside the FILES FOLDER is a File called EXAMPLE.JSON.
It reflected what was showing up on the screen when launching the project. I then messed with this file to add extra Fields and they showed when re-launching the Project. This is where I thought I was on the right track. However, they gave errors when trying to display Options 1 (Button). This is why I was digging around looking for "something else" that would make it work - Found Nothing as reported.
Here is basically the whole program (with reference to the Example.json file.
After this is the contents of the JSON File.
XUI VIEWS Sample Program:
Sub Process_Globals
Private xui As XUI
Private OptionsFile As String = "options.map"
End Sub
Sub Globals
Private prefdialog As PreferencesDialog
Private TextArea1 As B4XView
Private TextArea2 As B4XView
Private TextArea3 As B4XView
Private Options1, Options2, Options3 As Map
Private IME As IME
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
prefdialog.Initialize(Activity, "Preferences Dialog", 300dip, 300dip)
Options1.Initialize
Options2.Initialize
Options3.Initialize
xui.SetDataFolder ("preferences")
prefdialog.LoadFromJson(File.ReadString(File.DirAssets, "Example.json")) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
prefdialog.SetOptions("Cities", File.ReadList(File.DirAssets, "cities.txt"))
LoadSavedData
IME.Initialize("ime")
IME.AddHeightChangedEvent
End Sub
Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
prefdialog.KeyboardHeightChanged(NewHeight)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
SaveData
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
If prefdialog.BackKeyPressed Then Return True
End If
Return False
End Sub
Sub SaveData
Dim ser As B4XSerializator
File.WriteBytes(xui.DefaultFolder, OptionsFile, ser.ConvertObjectToBytes(Array(Options1, Options2, Options3)))
End Sub
Sub LoadSavedData
Try
If File.Exists(xui.DefaultFolder, OptionsFile) Then
Dim ser As B4XSerializator
Dim opt() As Object = ser.ConvertBytesToObject(File.ReadBytes(xui.DefaultFolder, OptionsFile))
Options1 = opt(0)
Options2 = opt(1)
Options3 = opt(2)
PrintOptions(Options1, TextArea1)
PrintOptions(Options2, TextArea2)
PrintOptions(Options3, TextArea3)
End If
Catch
Log(LastException)
End Try
End Sub
Sub btnOptions1_Click
Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
PrintOptions(Options1, TextArea1)
End If
End Sub
Sub btnOptions2_Click
Wait For (prefdialog.ShowDialog(Options2, "OK", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
PrintOptions(Options2, TextArea2)
End If
End Sub
Sub btnOptions3_Click
Wait For (prefdialog.ShowDialog(Options3, "OK", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
PrintOptions(Options3, TextArea3)
End If
End Sub
Sub PrintOptions (Options As Map, TextArea As B4XView)
Dim sb As StringBuilder
sb.Initialize
For Each key As String In Options.Keys
If key = "" Then Continue 'separators
sb.Append(key).Append(": ").Append(Options.Get(key)).Append(CRLF)
Next
Dim birthday As Long = Options.Get("Birthday")
Dim time As Period = Options.Get("Time")
sb.Append($"Date and time: $DateTime{DateUtils.AddPeriod(birthday, time)}"$).Append(CRLF)
TextArea.Text = sb.ToString
End Sub
I could not understand how to reference the data (which when saved, fills the lines of a textfield on the Phone - Am I meant to parse the textfield to extract the data ?
And I clearly don't understand how and where the fields I want to use are defined)
This is what the Example.JSON file contains (Attached in zip form below)
If so, you don't have to modify the .json manually, you can do it with this tool. You have to run this tool from B4J (it's free), then you can add, delete, modify the elements, and the tool will generate the .json you will add to your B4A app.
I guess I am. What the Tool does is simply make the JSON file. I had found the JSON File and had modified it directly - this worked, but my problem was a STUPID one - I duplicated one of the key names which caused problems. The project I am working with accepts all the data in fields on the screen - Really Nice. Then it saves the data in a TextArea. The main issue I am left with is - How do I access the values created by the JSON File - Do I simply parse the TextArea and get the values out that way ? (Seems like the only way possible from where I sit) I am a VB6 programmer so this is child's play using commands like INSTR and MID - There wouldn't just happen to be a list of Commands in B4X I could reference to. I am finding the "Books" very helpful, but not when looking for a specific command (You have to know the name of the command to see how it works - If you don't know its name then you hunt for hours trying to find what you are looking for). A neat Reference showing VB6 on one side and what B4X command is on the other, would be priceless for a VB6 programmer. Preferably with an example of how to use the B4X command. Perhaps too much to ask, but just asking if something like this exists.
Thanks so much for everyone's help on this - I feel I can deal with it easily now so long as I can find an equivalent to INSTR and MID commands in VB6