ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Developing an application or website / Controls, windows and pages / Controls: Available types / Native Container control
  • Overview
  • Training examples
  • Overview
  • Creating a button (native Java code)
  • Creating a button (native Kotlin code)
  • Creating a button (native Objective C code)
  • Handling the Native Container control with WLanguage properties
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
The Native Container control returns an handle/identifier:
Then, this handle can be used in the native code to manage the control.
The "Create" event of the Native Container control must contain the creation code of the displayed object.
AndroidiPhone/iPad Remark: The Native Container control cannot be tested via the "GO" option. You must compile and deploy the application.
Training examples

Overview

To start programming the Native Container control, let's see a training example to create a Button control. This example is meant to be simple, and the Button control comes as standard in WINDEV and WINDEV Mobile applications.
Android

Creating a button (native Java code)

The following code creates a button with the same size as the Native Container control.
  • Code for creating the Native Container control: This code calls a procedure available in native Java code for creating the view that will be displayed in the control.
    Android_AddButtonIntoNativeControl(MySelf.Value)
    Value corresponds to the view identifier.
  • Java code of the global procedure to create the view:
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;

    public static void Android_AddButtonIntoNativeControl(int nParentID)
    {
    Button button = new Button(getApplicationContext());
    button.setText("Hello world!");
    button.setOnClickListener(new View.OnClickListener()
    {
    @Override
    public void onClick(View v)
    {
    callProcedureWL("WLAndroid_DisplayInfo", "Hello world!");
    }
    });
    ViewGroup parent = (ViewGroup)getCurrentActivity().findViewById(nParentID);
    if(parent!= null)
    {
    parent.addView(button);
    }
    }
    In this example, the code can be divided into two sections:
    • the code for creating the view.
    • the code used to associate the view with the native Container control. This code must be adapted according to the type of created view (a button in this case) but it must always be found. This code uses the view identifier (nParentID) passed as parameter to the procedure. This code is as follows:
      ViewGroup parent = (ViewGroup)getCurrentActivity().findViewById(nParentID);
      if(parent!= null)
      {
      parent.addView(button);
      }
Remark: In the code for creating the view, the button uses the WLanguage WLAndroid_DisplayInfo procedure that is used to display a message. The code of this procedure is as follows:
PROCÉDURE WLAndroid_DisplayInfo(sInfo)
Info(sInfo)
For more details on how to use Java code in the code editor, see Using Java code.
Android

Creating a button (native Kotlin code)

The following code creates a button with the same size as the Native Container control.
  • Code for creating the Native Container control: This code calls a procedure available in native Java code for creating the view that will be displayed in the control.
    Android_AddButtonIntoNativeControl(MySelf.Value)
    Value corresponds to the view identifier.
  • Kotlin code of the global procedure to create the view:
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;

    fun KT_ButtonIntoNativeControl(nParentID: CBox)
    {
    var button = Button(getContexteApplication())
    button.setText("Written in Kotlin")
    button.setOnClickListener(View.OnClickListener()
    {
    callWLProcedure("WLAndroid_DisplayInfo", "Hello world!")
    })
    var parent: ViewGroup = getCurrentActivity().findViewById(nParentID)
    if(parent!= null)
    {
    parent.addView(button)
    }
    }
    In this example, the code can be divided into two sections:
    • the code for creating the view.
    • the code used to associate the view with the native Container control. This code must be adapted according to the type of created view (a button in this case) but it must always be found. This code uses the view identifier (nParentID) passed as parameter to the procedure. This code is as follows:
      var parent: ViewGroup = getCurrentActivity().findViewById(nParentID)
      if(parent!= null)
      {
      parent.addView(button)
      }
Remark: In the code for creating the view, the button uses the WLanguage WLAndroid_DisplayInfo procedure that is used to display a message. The code of this procedure is as follows:
PROCÉDURE WLAndroid_DisplayInfo(sInfo)
Info(sInfo)
For more details on how to use Kotlin code in the code editor, see Using Kotlin code.
iPhone/iPad

Creating a button (native Objective C code)

The following code is used to create a button in the native Container control.
  • Code for creating the Native Container control: This code calls a procedure available in native Objective C code for creating the view that will be displayed in the control. The button size is passed as parameter.
    IOS_AddButtonIntoNativeControl(MySelf.Value, 10, 10, 200, 60)
    Value corresponds to the view identifier.
  • Objective C code of global procedure used to create the view:
    • IOS_AddButtonIntoNativeControl procedure:
      void IOS_AddButtonIntoNativeControl(void *pParent, int x, int y, int width, int height)
      {
      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
      SimpleClass * pclClass = [[SimpleClass alloc] init];
      [button addTarget:pclClass action:@selector(onClick:)
      forControlEvents:UIControlEventTouchUpInside];
      [button setTitle:@"Hello world!" forState:UIControlStateNormal];
      button.frame = CGRectMake(x, y, width, height);
      [(UIView*)pParent addSubview:button];
      }
      In this example, the code can be divided into two sections:
      • the code for creating the view.
      • the code used to associate the view with the native Container control. This code must be adapted according to the type of created view (a button in this case) but it must always be found. This code uses the view identifier (pParent) passed as parameter to the procedure. This code is as follows:
        [(UIView*)pParent addSubview:button];
    • PlaceHolder procedure (used by the IOS_AddButtonIntoNativeControl procedure). CAUTION: This code must be placed BEFORE the code of global procedure IOS_AddButtonIntoNativeControl.
      #import "UIKit/UIKit.h"
      void PlaceHolder(){}
      @interface SimpleClass: NSObject
      @end
      @implementation SimpleClass

      - (void)onClick:(id)unused{
      [self performSelector:@selector(onClickDelayed:) withObject:unused afterDelay:0];
      }

      - (void)onClickDelayed:(id)unused{
      ClickOnNativeButton();
      }


      @end
  • WLanguage code called by the Objective C code, used to display a message during a click on the button.
    PROCÉDURE WLIOS_DisplayInfo() , ObjC
    Info("Click!")
For more details on how to use Objective C code in the code editor, see Using Objective C code.
Handling the Native Container control with WLanguage properties
The Native Container control can be handled by several WLanguage properties. For a complete list of WLanguage properties that can be used with a Native Container control, see Properties associated with Native Container controls.
Minimum version required
  • Version 23
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 04/04/2023

Send a report | Local help