Android Question AS Settings with segmented tab - how to set value in code?

Dave O

Well-Known Member
Licensed User
Longtime User
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:

B4X:
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:
B4X:
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:
B4X:
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
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

teddybear

Well-Known Member
Licensed User
...then in the B4XPage_Appear event, I try to set it to a value saved in a map. First I tried:
B4X:
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:
B4X:
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!
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.
prefs.MainPage.GetProperty("scoreToEnd").View.As(ASSegmentedTab).Index = settingsMap.Get("scoreToEnd") 'this doesn't work
I tested this, it works.
What is the value you get the map?
B4X:
settingsMap.Get("scoreToEnd")
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
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

teddybear

Well-Known Member
Licensed User
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.
Setting index, it will call the event AS_Settings1_ValueChanged
 

Attachments

  • Project.zip
    182.9 KB · Views: 1
Upvote 0
Top