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:
The template file is loaded with:
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.
'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
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:
'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
SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)
'Handle keyboard changes Sub Page1_KeyboardStateChanged (Height As Float) prefdialog.KeyboardHeightChanged(Height) End Sub
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.
V1.71 - Fix issue with 24 hours mode.
V1.66 - 24 hours mode for time items:
Set this mode with forms builder by writing 24 in the options field.
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.
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:
pref.SetEventsListener(Me, "Pref") 'sets the callback and event name.
'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 Map) As 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
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.
13 KB Views: 920
64.5 KB Views: 199
5.7 KB Views: 344
39.7 KB Views: 816