Skip to main content
MTana.1
Associate II
March 15, 2021
Solved

How to change screen by pressing button in ScrollList.

I placed the buttons which are made with custom container in ScrollList.

I'd like to change screen by pressing each button.

How should I write my code for pressing button and change screen?

I uploaded the sample project. Please see the attached for your reference.

Thank you.

This topic has been closed for replies.
Alexandre RENOUX
Alexandre RENOUXBest answer
Visitor II
March 22, 2021

Hello MTana.1,

I made a simple code example to show you how to change screen when pressing a button in a ScrollList. Looking at the code should give you all the necessary answers.

There's several ways to implement what you want, but the enclosed solution is in my opinion the simplest.

Basically,

  • You create change screen interactions (done in Designer) in your custom Container used as a base for your ScrollList.
  • You create an interaction (in Designer) that will trigger a virtual function when the button is clicked.
  • You assign a number to each element of your ScrollList to differentiate them and call the right screen change accordingly.

The main files to look at in the example are CustomContainer1.cpp/hpp and Screen1View.cpp/hpp

Hope this will help.

/Alexandre

7 replies

MM..1
Super User
March 15, 2021

Create interaction for change screen and assign it to dummy key.

Then in button call keyhandle.

static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(84);

MTana.1
MTana.1Author
Associate II
March 15, 2021

Thank you for prompt answer.

I'd like to know how to get interaction ​from custom container of ScrollList items.

Sorry, I'm touchgfx beginner.​

Thank you.​

MTana.1
MTana.1Author
Associate II
March 17, 2021

I have another related question.

I placed CustomContainer with 4 buttons in ScrollList. (4 buttons in 1 CustomContainer)

I'd like to change screen for each button. How to do?

0693W000008x8vZQAQ.pngThank you.

MM..1
Super User
March 17, 2021

As first i mean you missuse list. Scrollist is designed to repeat one same custom container in many elements, Then i mean simply you use one button in custom container usw...

Second is each object have defined own callbacks methods, that you need implement. For example list have :

void Screen2View::scrollList1UpdateItem(MenuItem &item, int16_t itemIndex) {
	if (itemIndex == cursorpos)
		item.selit(1);
	item.setLabel(touchgfx::TypedText(UI_Menu_Items_A[itemIndex]));
	item.setIco(touchgfx::Bitmap(UI_Menu_Icons_A[itemIndex]));
}

and next is for example callbacks for screen/buuton touch/click where you call switch screen directly or as i describe on first reply.

Best method for beginer is learn from example codes.

Alexandre RENOUX
Alexandre RENOUXBest answer
Visitor II
March 22, 2021

Hello MTana.1,

I made a simple code example to show you how to change screen when pressing a button in a ScrollList. Looking at the code should give you all the necessary answers.

There's several ways to implement what you want, but the enclosed solution is in my opinion the simplest.

Basically,

  • You create change screen interactions (done in Designer) in your custom Container used as a base for your ScrollList.
  • You create an interaction (in Designer) that will trigger a virtual function when the button is clicked.
  • You assign a number to each element of your ScrollList to differentiate them and call the right screen change accordingly.

The main files to look at in the example are CustomContainer1.cpp/hpp and Screen1View.cpp/hpp

Hope this will help.

/Alexandre

MTana.1
MTana.1Author
Associate II
March 22, 2021

Thank you for your great help.

I understand your project. It's very simple and helpful.

I'll try on my project.​

Alexandre RENOUX
Visitor II
March 23, 2021

Hello MTana.1,

Perfect, if it works on your project, please close this topic by choosing Select as Best.

/Alexandre