B4X Booklets
B4X CustomViews
Copyright: © 2022 Anywhere Software Edition 2.4
Last update: 2022.08.15
Table of contents 2 B4X CustomViews
1 General information ..................................................................................................................... 5
2 Class modules .............................................................................................................................. 6
2.1 Getting started ...................................................................................................................... 6
2.1.1 Adding a class module ..................................................................................................... 8
2.1.2 Polymorphism .................................................................................................................. 9
2.1.3 Self-reference ................................................................................................................. 10
2.1.4 Activity object B4A only ............................................................................................. 11
3 Standard class ............................................................................................................................. 12
3.1 Standard class structure ...................................................................................................... 12
4 CustomViews ............................................................................................................................. 14
4.1 CustomView types ............................................................................................................. 14
4.2 CustomView class structure ............................................................................................... 15
4.2.1 Event declarations .......................................................................................................... 16
4.2.2 Designer properties declarations .................................................................................... 16
4.2.3 Global variable declarations ........................................................................................... 16
4.2.4 Initialization routine ....................................................................................................... 17
4.2.5 Designer support routine DesignerCreateView ............................................................ 18
4.2.6 Accessing a CustomView from any container like xCustomListview .......................... 18
4.2.7 Routine to get the base Panel ......................................................................................... 19
4.3 Adding a custom view by code .......................................................................................... 20
4.4 Add properties .................................................................................................................... 21
4.5 Add Events ......................................................................................................................... 22
4.5.1 Code in the Class ............................................................................................................ 23
4.5.2 Event declaration in the class ......................................................................................... 24
4.5.3 Code in the calling module ............................................................................................ 24
4.6 Custom view and custom properties in the Designer ......................................................... 25
4.7 Add layouts to a CusomView ............................................................................................ 29
4.8 Libraries ............................................................................................................................. 30
4.8.1 Generate a B4X Library *.b4xlib .................................................................................. 31
4.8.1.1 AdditionalLibraries folder ...................................................................................... 32
4.8.1.2 Xml help files for B4X Libraries ........................................................................... 32
4.8.2 Complie to a product specific library ............................................................................. 34
4.8.2.1 Library specific attributes ...................................................................................... 36
4.8.2.2 Tip for MaterialIcons and Fontawesome fonts ...................................................... 38
4.9 Program flow ...................................................................................................................... 39
4.10 Intellisense help .................................................................................................................. 40
4.10.1 Comments before Sub Class_Globals ....................................................................... 40
4.10.2 Comments before a routine ........................................................................................ 40
4.10.3 Comments before an event routine ............................................................................ 41
4.11 CustomViews (XUI) .......................................................................................................... 42
4.11.1 CustomViews (XUI) class structure .......................................................................... 42
4.12 GetView ............................................................................................................................. 43
4.13 Add many CustomViews in the code ................................................................................. 44
5 First example xCustomButton................................................................................................... 46
5.1 Event declarations .............................................................................................................. 46
5.2 Custom properties for the Designer ................................................................................... 47
5.3 Class help header................................................................................................................ 47
5.4 Global variables ................................................................................................................. 48
5.5 Initialize routine ................................................................................................................. 49
5.6 DesignerCreateView routine .............................................................................................. 50
5.7 Base_Resize routine B4i / B4J only .................................................................................. 51
5.8 AddToParent routine .......................................................................................................... 52
5.9 InitClass routine ................................................................................................................. 53
Table of contents 3 B4X CustomViews
5.10 Click / LongClick event routines ....................................................................................... 54
5.11 Property routines ................................................................................................................ 55
5.12 Main code ........................................................................................................................... 56
5.12.1 Globals ....................................................................................................................... 56
5.12.2 Program start B4XPage_Created .............................................................................. 57
5.13 Click event routine ............................................................................................................. 57
5.14 Create the b4xlib library..................................................................................................... 58
6 XUI xLimitBar ........................................................................................................................... 59
6.1 Event declaration ................................................................................................................ 59
6.2 Custom properties for the Designer ................................................................................... 60
6.3 Global variables ................................................................................................................. 61
6.4 Initialize routine ................................................................................................................. 62
6.5 DesignerCreateView routine .............................................................................................. 63
6.6 Base_Resize routine B4i / B4J only .................................................................................. 64
6.7 AddToParent routine .......................................................................................................... 65
6.8 InitClass routine ................................................................................................................. 66
6.9 InitCursors routine ............................................................................................................. 66
6.10 Draw the background and background line ....................................................................... 67
6.11 DrawCursors routine .......................................................................................................... 68
6.12 Cursor moving .................................................................................................................... 69
6.13 Properties ........................................................................................................................... 70
6.14 Make a B4X Library .......................................................................................................... 72
Table of contents 4 B4X CustomViews
Main contributors: Klaus Christl (klaus) Erel Uziel (Erel).
To search for a given word or sentence use the Search function in the Edit menu.
All the source code and files needed (layouts, images etc.) of the example projects in this guide are
included in the SourceCode folder.
Updated for:
B4A version 11.80
B4i version 8.00
B4J version 9.80
B4X Booklets:
B4X Getting Started
B4X B4X Language
B4X IDE Integrated Development Environment
B4X Visual Designer
B4X Help tools
B4X CustomViews
B4X Graphics
B4X XUI B4X User Interface
B4X SQLite Database
B4X JavaObject NativeObject
B4XPages Cross-platform projects
B4R Example Projects
You can consult these booklets online in this link [B4X] Documentation Booklets.
Be aware that external links do not work in the online display.