Android Question ConfigureHomeWidget, can only be called once

mr23

Active Member
Licensed User
This error is generated when ConfigureHomeWidget is intended to be called once, but in a select or ifthenelse statement with multiple instances. Such as

if A then
ConfigureHomeWidget("litstring1",...)
else
ConfigureHomeWidget("litstring2",...)
End if

Such as one might do to select the layout used by a widget.
I'm guessing the literal string has to be compiled into the service, so the compiler will only accept one instance of the ConfigureHomeWidget("litstring",...) per service.

Can this be changed to accept either a string variable or ifthenelse/select ?
 

mr23

Active Member
Licensed User
Thanks for responding. I decided to move the widget code into a class, and create a service per widget. Each service still needs to have the rv_ routines as well as wrappers for all of the layout controls click event handlers, so almost 100 lines of (nearly) identical code between each service.

Sub Process_Globals
Dim widget As APWidgetClass
End Sub

Sub Service_Create
widget.Initialize(Me)
widget.rv = ConfigureHomeWidget("awidget4x2", "rv", 0, "A Widget")
End Sub
... handlers wrappers...
Just the layout string is different between several services widgets.

Would you consider a compile time construct/change something like the following

Sub Process_Globals
Dim widgetLayouts() As String
widgetLayouts = Array As String("awidget4x2", "awidget4x1", ... "awidget1x1")
End Sub

Sub Service_Create
rv = ConfigureHomeWidget(widgetLayouts, "rv", 0, "A Widget")
End Sub

So instead of the compiler currently generating just one service, it would generate N services, one for each layout in the array?
 

mr23

Active Member
Licensed User
Decided to use a helper class for most of the code, allowing the service modules (1 per widget format) to have just 1 line of code difference (ConfigureHomeWidget).
However, there is duplicated code in each service module, due to (I think) the requirement for the _Click handlers for buttons and imageviews to be in the service module; I would like to be able to specify the object that has the handler. Is that possible for B4X to implement? Each _Click event sub in my service modules calls the same named sub in my helper class object, if I could specify that to ConfigureHomeWidget that would be helpful to reduce code copy/paste/maintenance.

Sub imageviewN_Click
helper.imageviewN_Click
End Sub
 
Top