Android Question ConfigureHomeWidget, can only be called once

Discussion in 'Android Questions' started by mr23, Feb 3, 2015.

  1. mr23

    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 ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The compiler needs to create the XML files based on the layout file. You can use different build configurations with #IF to do it or use two services.
     
  3. mr23

    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?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You can post a feature request. Letting the compiler create multiple services is quite problematic.
     
  5. mr23

    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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You will need to keep these "dummy" event handlers. It is not possible to directly manage the widget events in other modules.
     
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