Dave O Well-Known Member Licensed User Longtime User May 5, 2026 #1 I'm trying out Alexander Stolte's AS Settings library for building preference pages (in my first B4XPages project). I've added the ASSegmentedTab extension and it works well in the UI, but I can't figure out how to set its value in code, and haven't found an example on the forum. In the B4XPage_Created event, I create the segmented tab: Code: prefs.MainPage.AddProperty_SegmentedTab("GeneralSettings", "scoreToEnd", "Points to win", "", Null, "10000", CreateMap("3000":1, "5000":2, "10000":3), 0) ...then in the B4XPage_Appear event, I try to set it to a value saved in a map. First I tried: Code: prefs.MainPage.GetProperty("scoreToEnd").Value = settingsMap.Get("scoreToEnd") ...but that didn't do anything, so I went back to the sample code and saw that I needed to drill down to the actual view and set its value, but tried this with no luck: Code: prefs.MainPage.GetProperty("player1Name").View.As(B4XView).Text = settingsMap.Get("player1Name") 'this works prefs.MainPage.GetProperty("scoreToEnd").View.As(ASSegmentedTab).Index = settingsMap.Get("scoreToEnd") 'this doesn't work Any tips? Thanks!
I'm trying out Alexander Stolte's AS Settings library for building preference pages (in my first B4XPages project). I've added the ASSegmentedTab extension and it works well in the UI, but I can't figure out how to set its value in code, and haven't found an example on the forum. In the B4XPage_Created event, I create the segmented tab: Code: prefs.MainPage.AddProperty_SegmentedTab("GeneralSettings", "scoreToEnd", "Points to win", "", Null, "10000", CreateMap("3000":1, "5000":2, "10000":3), 0) ...then in the B4XPage_Appear event, I try to set it to a value saved in a map. First I tried: Code: prefs.MainPage.GetProperty("scoreToEnd").Value = settingsMap.Get("scoreToEnd") ...but that didn't do anything, so I went back to the sample code and saw that I needed to drill down to the actual view and set its value, but tried this with no luck: Code: prefs.MainPage.GetProperty("player1Name").View.As(B4XView).Text = settingsMap.Get("player1Name") 'this works prefs.MainPage.GetProperty("scoreToEnd").View.As(ASSegmentedTab).Index = settingsMap.Get("scoreToEnd") 'this doesn't work Any tips? Thanks!
Dave O Well-Known Member Licensed User Longtime User Jun 7, 2026 #2 No answer (even from the library author) on this, and I can't get it to load values, so I'll have to build this page manually. That's a shame because the library was really good otherwise. Upvote 0
No answer (even from the library author) on this, and I can't get it to load values, so I'll have to build this page manually. That's a shame because the library was really good otherwise.
teddybear Well-Known Member Licensed User Jun 7, 2026 #3 Dave O said: ...then in the B4XPage_Appear event, I try to set it to a value saved in a map. First I tried: Code: prefs.MainPage.GetProperty("scoreToEnd").Value = settingsMap.Get("scoreToEnd") ...but that didn't do anything, so I went back to the sample code and saw that I needed to drill down to the actual view and set its value, but tried this with no luck: Code: prefs.MainPage.GetProperty("player1Name").View.As(B4XView).Text = settingsMap.Get("player1Name") 'this works prefs.MainPage.GetProperty("scoreToEnd").View.As(ASSegmentedTab).Index = settingsMap.Get("scoreToEnd") 'this doesn't work Any tips? Thanks! Click to expand... No answer (even from the library author) on this, and I can't get it to load values, so I'll have to build this page manually. Click to expand... prefs.MainPage.GetProperty("scoreToEnd").View.As(ASSegmentedTab).Index = settingsMap.Get("scoreToEnd") 'this doesn't work Click to expand... I tested this, it works. What is the value you get the map? B4X: settingsMap.Get("scoreToEnd") Upvote 0
Dave O said: ...then in the B4XPage_Appear event, I try to set it to a value saved in a map. First I tried: Code: prefs.MainPage.GetProperty("scoreToEnd").Value = settingsMap.Get("scoreToEnd") ...but that didn't do anything, so I went back to the sample code and saw that I needed to drill down to the actual view and set its value, but tried this with no luck: Code: prefs.MainPage.GetProperty("player1Name").View.As(B4XView).Text = settingsMap.Get("player1Name") 'this works prefs.MainPage.GetProperty("scoreToEnd").View.As(ASSegmentedTab).Index = settingsMap.Get("scoreToEnd") 'this doesn't work Any tips? Thanks! Click to expand... No answer (even from the library author) on this, and I can't get it to load values, so I'll have to build this page manually. Click to expand... prefs.MainPage.GetProperty("scoreToEnd").View.As(ASSegmentedTab).Index = settingsMap.Get("scoreToEnd") 'this doesn't work Click to expand... I tested this, it works. What is the value you get the map? B4X: settingsMap.Get("scoreToEnd")
Dave O Well-Known Member Licensed User Longtime User Jun 7, 2026 #4 Which code worked for you - setting Value or setting Index? I tried every variation I could think of but could not get it to work. I also tried tying the segmentedTab that I referenced through GetProperty directly to a singleton ASSegmentedTab, but still couldn't get the former to change to a specified index/value. Upvote 0
Which code worked for you - setting Value or setting Index? I tried every variation I could think of but could not get it to work. I also tried tying the segmentedTab that I referenced through GetProperty directly to a singleton ASSegmentedTab, but still couldn't get the former to change to a specified index/value.
teddybear Well-Known Member Licensed User Jun 7, 2026 #5 Dave O said: Which code worked for you - setting Value or setting Index? I tried every variation I could think of but could not get it to work. I also tried tying the segmentedTab that I referenced through GetProperty directly to a singleton ASSegmentedTab, but still couldn't get the former to change to a specified index/value. Click to expand... Setting index, it will call the event AS_Settings1_ValueChanged Attachments Project.zip Project.zip 182.9 KB · Views: 118 Upvote 0
Dave O said: Which code worked for you - setting Value or setting Index? I tried every variation I could think of but could not get it to work. I also tried tying the segmentedTab that I referenced through GetProperty directly to a singleton ASSegmentedTab, but still couldn't get the former to change to a specified index/value. Click to expand... Setting index, it will call the event AS_Settings1_ValueChanged
Dave O Well-Known Member Licensed User Longtime User Jun 9, 2026 #6 Thanks, I got it working after you confirmed that setting Index worked. The actual problem was not setting Index as such, but setting it in the B4XPage_Created sub. When I moved it to the B4XPage_Appear sub, it worked fine. I assume this is kind of like trying to handle views in the B4A Activity_Create sub after loading the layout. Sometimes the views are not ready to handle, so it's best to put that kind of code in Activity_Resume. Anyway, got it working, so I think I can use AS Settings instead of rolling my own. In which case I hope I can get a response from @Alexander Stolte so I can donate to him. Upvote 0
Thanks, I got it working after you confirmed that setting Index worked. The actual problem was not setting Index as such, but setting it in the B4XPage_Created sub. When I moved it to the B4XPage_Appear sub, it worked fine. I assume this is kind of like trying to handle views in the B4A Activity_Create sub after loading the layout. Sometimes the views are not ready to handle, so it's best to put that kind of code in Activity_Resume. Anyway, got it working, so I think I can use AS Settings instead of rolling my own. In which case I hope I can get a response from @Alexander Stolte so I can donate to him.
Dave O Well-Known Member Licensed User Longtime User Jun 13, 2026 #7 The plot thickens: This works fine on most phones, but crashes on my Samsung Note 10+ and S24 Ultra when I try to access one of the segmentedTab view values (view is null). I get very nervous when basic functions like setting a UI view's value crash. Upvote 0
The plot thickens: This works fine on most phones, but crashes on my Samsung Note 10+ and S24 Ultra when I try to access one of the segmentedTab view values (view is null). I get very nervous when basic functions like setting a UI view's value crash.
Dave O Well-Known Member Licensed User Longtime User Jun 14, 2026 #8 So I solved this (again?) by using AddPageAndCreate instead of AddPage. (The latter only creates the page on ShowPage, while the former apparently gives the views more time to get fully instantiated. To recap: I call AddPageAndCreate, then ShowPage later. In the preferences page, in B4XPage_Created, I add the various fields using AddProperty_XXXX. In B4XPage_Appear, I set the segments' GetProperty("XXX").Value to the corresponding settings from my map. I call prefs.MainPage.Refresh (phew!) Upvote 0
So I solved this (again?) by using AddPageAndCreate instead of AddPage. (The latter only creates the page on ShowPage, while the former apparently gives the views more time to get fully instantiated. To recap: I call AddPageAndCreate, then ShowPage later. In the preferences page, in B4XPage_Created, I add the various fields using AddProperty_XXXX. In B4XPage_Appear, I set the segments' GetProperty("XXX").Value to the corresponding settings from my map. I call prefs.MainPage.Refresh (phew!)