cancel
Showing results for 
Search instead for 
Did you mean: 

How to get list layout click value

YCF.1
Associate III

I can use listLayout add() item and remove() item good, but I don't know

how to get selected item number on callBackHandler()?

Have any example for me to study ?​

void Screen2View::callBackHandler(CustomContainer2 & cc_1)

{

listLayout1.remove(cc_1);

invalidate();

}

Thank you & Best regards,

1 ACCEPTED SOLUTION

Accepted Solutions
Yoann KLEIN
ST Employee

Hello @YCF.1​ ,

A good starting point is to analyze the ListLayout example in TouchGFXDesigner.

You will see in MainView.cpp that a callback "listElementClicked" is implemented. This method will be called every time the user clicks on the button "Delete" and provides the specific CustomListElement object that was clicked. That's already a good way to isolate each element of your list.

Then, if you want to get the specific index of the clicked element of your list, you can try that :

  • Declare an integer variable in CustomListElement.hpp, like this :
int itemIndex;
  • Modify the setupListElement(const Bitmap&,TEXTS) method to include that new parameter.
void setupListElement(const Bitmap& iconBMP, TEXTS iconTextID, int elementIndex);
  • In CustomListElement.cpp, also modify the setupListElement(const Bitmap&,TEXTS) method to allow the user to store the items indexes in this class.
void CustomListElement::setupListElement(const Bitmap& iconBMP, TEXTS iconTextID, int elementIndex)
{
    itemIndex = elementIndex;
    icon.setBitmap(iconBMP);
    text.setTypedText(TypedText(iconTextID));
    text.resizeToCurrentText();
    invalidate();
}
  • Then, in MainView.cpp, fix the call of this function in the setupScreen() method. For instance, there is the function to define the Bitmap and text displayed on the first element. I just defined the element index at "0" here.
listElements[0].setupListElement(Bitmap(BITMAP_ICON0_ID) , T_LIST_ELEMENT_00 , 0);
  • Finally, in the listElementClicked(CustomListElement&) function, you can get the selected item number like this :
int item_nr = element.itemIndex; // "element" is a CustomListElement here

I will also join my project to this post, it might be easier for your understanding.

Let me know if that helped or if you have other questions,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX

View solution in original post

3 REPLIES 3
Yoann KLEIN
ST Employee

Hello @YCF.1​ ,

A good starting point is to analyze the ListLayout example in TouchGFXDesigner.

You will see in MainView.cpp that a callback "listElementClicked" is implemented. This method will be called every time the user clicks on the button "Delete" and provides the specific CustomListElement object that was clicked. That's already a good way to isolate each element of your list.

Then, if you want to get the specific index of the clicked element of your list, you can try that :

  • Declare an integer variable in CustomListElement.hpp, like this :
int itemIndex;
  • Modify the setupListElement(const Bitmap&,TEXTS) method to include that new parameter.
void setupListElement(const Bitmap& iconBMP, TEXTS iconTextID, int elementIndex);
  • In CustomListElement.cpp, also modify the setupListElement(const Bitmap&,TEXTS) method to allow the user to store the items indexes in this class.
void CustomListElement::setupListElement(const Bitmap& iconBMP, TEXTS iconTextID, int elementIndex)
{
    itemIndex = elementIndex;
    icon.setBitmap(iconBMP);
    text.setTypedText(TypedText(iconTextID));
    text.resizeToCurrentText();
    invalidate();
}
  • Then, in MainView.cpp, fix the call of this function in the setupScreen() method. For instance, there is the function to define the Bitmap and text displayed on the first element. I just defined the element index at "0" here.
listElements[0].setupListElement(Bitmap(BITMAP_ICON0_ID) , T_LIST_ELEMENT_00 , 0);
  • Finally, in the listElementClicked(CustomListElement&) function, you can get the selected item number like this :
int item_nr = element.itemIndex; // "element" is a CustomListElement here

I will also join my project to this post, it might be easier for your understanding.

Let me know if that helped or if you have other questions,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX

Hi! Yoann KLEIN

I follow your advice can to get index of item of list Layout.

Thanks!

Hi! Yoann KLEIN!

I retry again to create new List Layout on screen main page.

I click list's button but no callback to remove list layout item.

  

I check below file :

MainView.hpp / MainView.cpp

CustomListElement.hpp / CustomListElement.cpp

I don't know what is mistake on my code, can you help me.

Thank you & Best regards.