PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

This page concerns the 23 + version of WINDEV, WINDEV Mobile. Upgrade your version.
  • Overview
  • Training examples
  • Overview
  • Creating a button
  • Creating a button
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Handling a Native Container control by programming
Overview
The Native Container control returns an handle/identifier:
Then, this handle can be used in the native code to manage the control.
The "Creating XXX" process associated with the control must contain the creation code of the object displayed in the Native Container control.
AndroidiPhone/iPad Note: The test of Native Container control cannot be run in GO mode. You must compile and deploy the application.
Training examples

Overview

To present the programming of Native Container control, let's see a training example used to create a Button control. This example is voluntarily simple, and the Button control exists in standard in the WINDEV and WINDEV Mobile applications.
Android

Creating a button

The following code is used to create a button whose size is identical to the one of 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 global procedure used 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 is using the view identifier (nParentId) passed in parameter to the procedure. This code is as follows:
      ViewGroup parent = (ViewGroup)getCurrentActivity().findViewById(nParentId);
      if(parent!= null)
      {
      parent.addView(button);
      }
Note: In the code for creating the view, the button is using the WLanguage WLAndroid_DisplayInfo procedure that is used to display a message. The code of this procedure is as follows:
PROCEDURE WLAndroid_DisplayInfo(sInfo)
Info(sInfo)
iPhone/iPad

Creating a button

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 in 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 is using the view identifier (pParent) passed in 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
  • WLangage code called by the Objective C code, used to display a message during a click on the button.
    PROCEDURE WLIOS_DisplayInfo() , ObjC
    Info("Click!")
Handling the Native Container control with WLanguage properties
The Native Container control can be handled by several WLanguage properties. To find out the entire list of WLanguage properties that can be used with a Native Container control, see Properties associated with the Native Container control.
Minimum required version
  • Version 23
This page is also available for…
Comments
Click [Add] to post a comment