B4A Library B4A Activity Context ( Views by Name )

stefanobusetto

Active Member
Licensed User
This library helps accessing views of an activity.
Views can be accessed by name (GetViewByName)

The library is part of the xnObjects library (version 2.55 and above).
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/

B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ctx As b4aActivityContext
ctx.Initialize ( Activity )
End Sub

Sub Activity_Create(FirstTime As Boolean)
ctx.AddViewButton   ( "uno" , "b" ,  10dip ,  10dip , 120dip , 60dip )
ctx.AddViewButton   ( "due" , "c" ,  10dip ,  70dip , 120dip , 60dip )
ctx.AddViewEditText ( "tre" , "b" , 170dip ,  10dip , 120dip , 60dip )
ctx.AddViewEditText ( "qua" , "b" , 170dip ,  70dip , 120dip , 60dip )
ctx.AddViewButton   ( "zzz" , "c" ,  10dip , 140dip ,  60dip , 60dip )

ctx.AddViewSpinner  ( "sp"  , "s" ,  10dip , 210dip , 240dip , 49dip )
ctx.AddViewCheckBox ( "cb"  , "s" ,  10dip , 260dip , 240dip , 40dip )
ctx.AddViewLabel    ( "lb"  , "s" ,  10dip , 300dip , 240dip , 40dip )

If ctx.ViewExistsButton("uno") Then
   ctx.ViewGetButton("uno").Text = "uno"
End If

If ctx.ViewExistsEditText("tre") Then
   ctx.ViewGetEditText("tre").Text = "tre"
End If

If ctx.ViewExistsLabel("lb") Then
   ctx.ViewGetLabel("lb").Text = "lb"
End If

If ctx.ViewExistsCheckBox("cb") Then
   ctx.ViewGetCheckBox("cb").Text = "cb"
End If

If ctx.ViewExistsSpinner("sp") Then
   ctx.ViewGetSpinner("sp").Add("uno")
   ctx.ViewGetSpinner("sp").Add("due")
   ctx.ViewGetSpinner("sp").Add("tre")
   ctx.ViewGetSpinner("sp").Add("quattro")
End If
End Sub
If you like my work.
You can support the development.
 
Last edited:
Top