Explanation of associated functions automatically generated by controls

Some controls will automatically generate associated functions. The specific explanation of the associated functions generated by these controls is as follows :

[!Note] The XXXX in the function represents the control ID, please replace it yourself in the actual process


  • Button control

     static bool onButtonClick_XXXX(ZKButton *pButton) {
        return false;
     }
    

    When the button is clicked, this function is called.

    • The parameter ZKButton *pButton is the pointer of the clicked button. A series of operations can be performed on the control through the member functions of the pointer. This pointer is the same object as the object pointed to by the global variable mXXXXPtr.

  • Edit Text control

    static void onEditTextChanged_XXXX(const std::string &text) {
    
    }
    

    When the text in the Edit Text box changes, the system will automatically call this function.

    • Parameter std::string &text is the complete string in the current Edit Text box.

  • Seek Bar control

    static void onProgressChanged_XXXX(ZKSeekBar *pSeekBar, int progress) {
    
    }
    

    When the current progress value of the Seek bar changes, the system will automatically call this function.

    • Parameter ZKSeekBar *pSeekBar is the pointer of the Seek Bar control, and a series of operations can be performed on the control through the member functions of the pointer.
    • Parameter int progress is the progress value of the current Seek Bar

  • Slide window control

    static void onSlideItemClick_XXXX(ZKSlideWindow *pSlideWindow, int index) {
    
    }
    

    When you click an icon in the sliding window control, the system will automatically call this function.

    • Parameter ZKSlideWindow *pSlideWindow is the pointer of the slide window control, and a series of operations can be performed on the control through the member functions of the pointer.
    • Parameter int index is the index value of the currently clicked icon. For example, a total of 10 icons are added to the slide window, and the index value range is [0, 9]

  • List control

    The list control is the most complex control, it will create three associated functions. Although there are many functions, it is very easy to understand according to the following steps.

    1. First, if the system wants to draw a list control, it needs to know how many items it has. So there is the following correlation function

       static int getListItemCount_XXXX(const ZKListView *pListView) {
             return 0;
       }
      
    2. Parameter const ZKListView *pListView is the pointer of the list control, which points to the same object as the global variable mXXXXPtr.

    3. Return value is an integer, which means how many items there are in the list, which can be defined according to your needs.

    4. After the system knows the number that needs to be drawn, it is not enough. It also needs to know what content you display for each item. So with the following function, it will be called multiple times, allowing you to set the display content of each item until each item is processed.

      void obtainListItemData_XXXX(ZKListView *pListView, ZKListView::ZKListItem *pListItem, int index) {
       //pListItem->setText(index)
      }
      
      • Parameter ZKListView *pListView is the pointer of the list control, which points to the same object as the global variable mXXXXPtr.
      • Parameter ZKListView::ZKListItem *pListItem is the pointer of the list item, corresponding to the Item in the UI file
      • Parameter int index is the index value of pListItem in the entire list. It has a certain range. For example: The return value of the getListItemCount_XXXX function is 10, which means there are 10 items in the list. Then the range of index is [0, 9], combining pListItem and index, you can know where the list item you set now is in the entire list.
        In this function, you can set the display content of each item separately according to index.
        For example: The commented statement in the function means: each list item displays its corresponding index number as text.
  1. Similar to the button control, the list control also has a click event, but it judges which list item is currently clicked based on the index value.

    static void onListItemClick_XXXX(ZKListView *pListView, int index, int id) {
       //LOGD(" onListItemClick_ Listview1  !!!\n");
    }
    

    When the list control is clicked, the system will calculate the index number of the list item and will automatically call this function.

    • Parameter ZKListView *pListView is the pointer of the list control, which points to the same object as the global variable mXXXXPtr.
    • Parameter int index is the index value of the currently clicked list item in the entire list control
    • Parameter int id is the id of the currently clicked control. Note that this id is different from the ID name in the attribute table. Its specific macros are defined in the corresponding Activity.h file. For example in mainActivity.h

    ID宏定义
    The function of this id parameter is that when there are multiple sub-items in the list item, it can be used to distinguish which sub-item is currently clicked.
    For example: As shown in the figure below, I added two list items to the list item and added a picture decoration as a switch button. The attribute ID names are SubItem1 and SubItem2 respectively. When I click on SubItem1 in the case of, by judging the equal relationship between the parameter id and ID_MAIN_SubItem1 and ID_MAIN_SubItem2, which switch is clicked can be determined.
    Example code :

    static void onListItemClick_XXXX(ZKListView *pListView, int index, int id) {
       //LOGD(" onListItemClick_ Listview1  !!!\n");
       switch(id) {
       case ID_MAIN_SubItem1:
           //LOGD("Clicked the first subitem of item %d in the list", index);
           break;
       case ID_MAIN_SubItem2:
           //LOGD("Clicked the second subitem of item %d in the list", index);
           break;
       }
    }
    

    列表outline 列表子项示例

powered by Gitbooklast modified: 2020-12-08 18:24:17

results matching ""

    No results matching ""