cancel
Showing results for 
Search instead for 
Did you mean: 

How to change screen by pressing button in ScrollList.

MTana.1
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Alexandre RENOUX
Principal

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

View solution in original post

7 REPLIES 7
MM..1
Chief II

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
Associate III

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
Associate III

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
Chief II

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
Principal

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
Associate III

Thank you for your great help.

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

I'll try on my project.​

Hello MTana.1,

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

/Alexandre