Android Question B4XPreferences Field Sizes and Presentation

Intelemarketing

Active Member
Licensed User
Longtime User
I am using B4XPreferences to enter a series of questions
It is controlled by a JSON File (Picture of Example.json attached)

It is all working, but some of the fields in the Template are very short.
The field I am most concerned with is called "Option"
This causes a drop down list to appear, from which you select a Country.
The Country Field, displayed on the screen is too short so it gets wrapped and chopped, even though there is plenty of space to display it

Picture of the B4XPreferences questions attached

Question 1 is - Is it possible to have a wider field space to display the selection of the country ? (Country Name is 4th Field on the screen)
Question 2 is - Is it possible to amend the Font and font size of the field below it (Your Phone No)

(I am assuming that the settings are fixed inside the B4XPreferences Library)

Thanks for any advice
 

Attachments

  • OPTIONS1.JPG
    OPTIONS1.JPG
    52.7 KB · Views: 151
  • examplejson.JPG
    examplejson.JPG
    73.7 KB · Views: 154

Mahares

Expert
Licensed User
Longtime User
Question 1 is - Is it possible to have a wider field space to display the selection of the country ? (Country Name is 4th Field on the screen)
If you check the Objects\b4xlibs\files subfolder of your project, you will see many .bal files. I usually copy the one I want in this case: shortoptions.bal to the assets and modify the layout by expanding the height of the combo. This may not be the preferred way of doing it,, Perhaps Erel has a better and more legitimate way of doing it.
Question 2 is - Is it possible to amend the Font and font size of the field below it (Your Phone No)
B4X:
For i = 0 To prefdialog.PrefItems.Size - 1
        Dim pi As B4XPrefItem = prefdialog.PrefItems.Get(i)    
        If pi.ItemType = prefdialog.TYPE_TEXT Then   'if phone set up as number: prefdialog.TYPE_NUMBER
            Dim ft As B4XFloatTextField = prefdialog.CustomListView1.GetPanel(i).GetView(0).Tag
            ft.TextField.Font = xui.CreateDefaultBoldFont(24)
            ft.TextField.TextColor =xui.Color_Magenta
        End If
    Next
 
Upvote 0

Intelemarketing

Active Member
Licensed User
Longtime User
Thank you Mahares for the code.
I have been hunting through the Forums and have found a number of references to Font Sizes, Lengths in B4XPreferences
but none of them seem to help me - most of the time I am getting screeds of RED Logs from Java which is telling me that I
don't understand how to place the code/ use the code.

Can you tell me where I should insert it please ?

I greatly appreciate your advice
Cheers
George


STARTUP CODE WHERE I LOAD MY SETTINGS :
Sub Activity_Create(FirstTime As Boolean)
    Try
        Activity.LoadLayout("1")
        prefdialog.Initialize(Activity, "MyApp Settings", 350dip, 350dip)
  
        Options1.Initialize
      
    xui.SetDataFolder ("preferences")
    prefdialog.LoadFromJson(File.ReadString(File.DirAssets, "Example.json"))
    prefdialog.SetOptions("Cities", File.ReadList(File.DirAssets, "cities.txt"))
    prefdialog.SetOptions("Countries", File.ReadList(File.DirAssets, "countries.txt"))

        LoadSavedData

End Sub

Then later I can click on a button to Change the Settings - This is where some of the Field Lengths are Too Short

SETTINGS ARE DISPLAYED AND I CAN ENTER/CHANGE SETTINGS - DATA THEN SAVED:
Sub btnSettings_Click
    Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int)
  
  
    If Result = xui.DialogResponse_Positive Then
        PrintOptions(Options1, TextArea1)
        MySettings = TextArea1.Text
      
        SaveData

'Settings are then displayed in a Message Box while I am debugging my App

        Dim sf As Object = xui.MsgboxAsync(MySettings  ,"My Settings")
        Wait For (sf) Msgbox_Result (Result As Int)

    End If

End Sub
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Can you tell me where I should insert it please ?
The code snippet I put in post#2 should go immediately after this line: Sub btnSettings_Click.
But to expand the widths and heights, you have to modify the layouts I referred to in post#
EDIT: 10132020: Apparently, there is a desktop form builder that helps build layouts and templates. I have not used it, and not familiar with it. It maybe a better solution than changing the .bal layout files I have alluded to in previous post.
 
Last edited:
Upvote 0

Intelemarketing

Active Member
Licensed User
Longtime User
I inserted the code at the point as instructed, and it is giving an error on the instruction below

PROGRAM SHUTS DOWN ON THIS INSTRUCTION - Line 11:
Sub btnSettings_Click
 
    For i = 0 To prefdialog.PrefItems.Size - 1
        Dim pi As B4XPrefItem = prefdialog.PrefItems.Get(i)
        If pi.ItemType = prefdialog.TYPE_TEXT Then                                        'if phone set up as number: prefdialog.TYPE_NUMBER
         
            Dim ic As Object = xui.MsgboxAsync(i, "Item Count")         '<<<<<<<<<<<<<< Item Count was Number 4 (Option Field)
            Wait For (ic) Msgbox_Result (Result As Int)
         

            Dim ft As B4XFloatTextField = prefdialog.CustomListView1.GetPanel(i).GetView(0).Tag    '<<<<<<<<<<<<<<<<<< shut down >>>>>>>>>>>'
            ft.TextField.Font = xui.CreateDefaultBoldFont(24)
            ft.TextField.TextColor =xui.Color_Magenta
        End If
    Next
 
    Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        PrintOptions(Options1, TextArea1)
        MySettings = TextArea1.Text
     
        SaveData
     
        Dim sf As Object = xui.MsgboxAsync( MySettings  ,"MyApp Settings")
        Wait For (sf) Msgbox_Result (Result As Int)
    End If
End Sub

There were no errors or anything at all in the Log File (except for the Connection to my phone)

Not sure how to proceed - sorry for being a pest
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I inserted the code at the point as instructed, and it is giving an error on the instruction below
I am really not too well versed on the subject. My project is simple, that is why I managed to make it work. Your best bet is to reproduce the problem in a project and upload to the forum. Someone with more knowledge with B4XPreferenceDIalog can probably spot the issue and help you solve it.
 
Upvote 0
Top