B4A Library [B4X] B4XPreferencesDialog - Cross platform forms

Discussion in 'Additional libraries, classes and official updates' started by Erel, Mar 18, 2019.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]



    B4XPreferencesDialog makes it easy to create dialogs with all kinds of input fields.

    The main steps required to use these dialogs are:

    1. Define the list of fields. The recommended way to do it is with Forms Builder tool:

    https://www.b4x.com/android/forum/t...der-designer-for-b4xpreferencesdialog.104670/

    The template file is loaded with:
    Code:
    prefdialog.LoadFromJson(File.ReadString(File.DirAssets, "Example.json"))
    Note that you can either set the list of options inside the template or programmatically by calling SetOptions.

    2. Call ShowDialog and pass the data map. It can be an empty map or a map where some of the fields are already set.
    Code:
    'Options1 is a Map object
    Wait For (prefdialog.ShowDialog(Options1, "OK""CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
       PrintOptions(Options1, TextArea1)
    End If
    The data map will be updated when the user clicks on the OK button.

    You can use the same dialog to show different data maps. See the attached examples. The examples also show how to save and load the data maps using B4XSerializator.

    Platform specific instructions:

    B4A

    Code:
    'Handle the back key
    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

    'Handle keyboard changes:
    Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
       prefdialog.KeyboardHeightChanged(NewHeight)
    End Sub
    Manifest editor:
    Code:
    SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)
    B4i

    Code:
    'Handle keyboard changes
    Sub Page1_KeyboardStateChanged (Height As Float)
       prefdialog.KeyboardHeightChanged(Height)
    End Sub
    Dependencies:

    XUI Views v2.05+
    : https://www.b4x.com/android/forum/threads/100836/#content
    Note that XUI Views is an internal library in B4J and B4A. It will be an internal library in the next version of B4i.
    You must select it in the libraries tab.

    xCustomListView v1.70+:
    https://www.b4x.com/android/forum/threads/84501
    xCustomListView is an internal library.

    Updates

    V1.65 - New Explanation item. This is a non-editable item that can be used to provide more information. Note that the explanation text is part of the template. It can be set with the form builder or at runtime (when the item is added or with the new SetExplanation method).
    V1.62 - Fixes an issue in B4A where the dialog can scroll to one of the text fields after returning from an inner dialog.
    V1.61 - Fixes an issue with numeric range fields not being set.
    V1.60 - Two new item types: Time and Numeric Range.

    [​IMG]
    Depends on XUI Views v2.05+.

    The Time item returns a Period object. The attached examples show how to use it to get a date and time value.

    V1.50 - Two new item types: Multiline Text and Decimal Number.
    - Bug fix related to the light theme and text fields.
    - Empty non-required numeric fields are not treated as invalid values. Note that the returned map will not include keys with empty string values.

    V1.40 - Adds an IsValid event that you can use to validate the data before it is committed.
    In order to use it you need to first call:
    Code:
    pref.SetEventsListener(Me, "Pref"'sets the callback and event name.
    Handle the event:
    Code:
    'Number value should be between 1 to 50. If not we call ScrollToItemWithError and return False.
    'You can check all fields here.
    Sub Pref_IsValid (TempData As MapAs Boolean
       
    Dim number As Int = TempData.GetDefault("Number"0)
       
    If number < 1 Or number > 50 Then
           pref.ScrollToItemWithError(
    "Number")
           
    Return False
       
    End If
       
    Return True
    End Sub
    V1.30 - Support for dark and light themes. Set it with the form builder or the Theme property.

    XUI Views v2.00+ is now required.

    V1.20 - Support for json templates, required fields and other minor improvements.
    V1.10 - New ShortOptions item based on B4XComboBox. This item is useful when there are a few options to choose from (unlike Options item which opens a new dialog and is more suitable for larger lists).
    Other bug fixes and improvements.
     

    Attached Files:

    Last edited: Jul 4, 2019
    hatzisn, ocalle, wyatt420 and 32 others like this.
  2. makis_best

    makis_best Active Member Licensed User

    How I can make Monday first day of the week when I use
    prefdialog.AddDateItem("Birthday", "Birthday")
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Add this:
    Code:
    p.DateTemplate.Initialize
    p.DateTemplate.FirstDay = 
    1
     
    ocalle likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. incendio

    incendio Well-Known Member Licensed User

    ocalle likes this.
  6. Erel

    Erel Administrator Staff Member Licensed User

    V1.40 - Adds an IsValid event that you can use to validate the data before it is committed.
    In order to use it you need to first call:
    Code:
    pref.SetEventsListener(Me, "Pref"'sets the callback and event name.
    Handle the event:
    Code:
    'The value in the field named 'Number' should be between 1 to 50. If not we call ScrollToItemWithError and return False.
    'You can check all fields here.
    Sub Pref_IsValid (TempData As MapAs Boolean
       
    Dim number As Int = TempData.GetDefault("Number"0)
       
    If number < 1 Or number > 50 Then
           pref.ScrollToItemWithError(
    "Number")
           
    Return False
       
    End If
       
    Return True
    End Sub
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    V1.50 - Two new items types: multiline Text and decimal number.
    - Bug fix related to the light theme and text fields.
    - Empty non-required numeric fields are not treated as invalid values. Note that the returned map will not include keys with empty string values.
     
    jimmyF and Claudio Oliveira like this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    V1.60 - Two new item types: Time and Numeric Range.

    [​IMG]
    Depends on XUI Views v2.05+.
     
    ocalle and maXim like this.
  9. Erel

    Erel Administrator Staff Member Licensed User

    V1.61 - Fixes an issue with numeric range fields not being set.
     
    naifnas likes this.
  10. Erel

    Erel Administrator Staff Member Licensed User

    V1.62 - Fixes an issue in B4A where the dialog can scroll to one of the text fields after returning from an inner dialog.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    V1.65 - New Explanation item. This is a non-editable item that can be used to provide more information. Note that the explanation text is part of the template. It can be set with the form builder or at runtime (when the item is added or with the new SetExplanation method).
     
    DonManfred and peacemaker like this.
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice