一、ClickListener介绍
ClickListener就是点击监听器事件,当控件接收到单击事件时调用该事件。
二、touchGFX工程搭建
工程中添加image控件
勾选ClickListener选项
三、工程源码修改
1、Screen1View.hpp
添加事件处理函数
Callback<Screen1View, const touchgfx::Image & , const touchgfx::ClickEvent &> imageClickHandler;
void image_click_handler(const touchgfx::Image &image , const touchgfx::ClickEvent &event);
注意格式要一样哦
2、Screen1View.cpp
首先初始化imageClickHandler
imageClickHandler(this,&Screen1View::image_click_handler)
然后为image控件添加点击处理回调函数
image1.setClickAction(imageClickHandler);
实现回调函数
#include "rtthread.h"
void Screen1View::image_click_handler(const touchgfx::Image &image , const touchgfx::ClickEvent &event)
{
if(&image == &this->image1)
{
if(event.getType() == ClickEvent::PRESSED)
{
rt_kprintf("PRESSED\r\n");
}
else if(event.getType() == ClickEvent::RELEASED)
{
rt_kprintf("RELEASED\r\n");
}
}
}