cancel
Showing results for 
Search instead for 
Did you mean: 

Update texts in a scrollist embedded in a scrolllist

PDe N.1
Associate

Hello,

I created a scrolllist where each item (container) contains a scrolllist with subitems (containers).

Items and subitems have text areas which need to be updated. 

I know how to update texts in the items using "ScrolllistUpdateItem" in the Screenview but I can figure out how to do the same for the embedded scrolllists.

I don't know how to update the texts in the subitems.

Actually I don't even know if it is possible.

Any suggestions?

Thanks

Have a good day

Pietro

2 REPLIES 2
Alexandre RENOUX
Principal

Hello,

You do the same as you would with only one ScrollList except that this time, it's not in the View that you implement the ScrollListUpdateItem but in the ScrollList that include the other one.

For ease of understanding I did a quick example that you will find enclosed to this message.

Note : I don't know why you are trying to have a scrollList inside a scrollList but I don't recommend it. As soon as you want to interact with items this gets quite complicated and if you don't have extensive C++ and TouchGFX knowledge, you can have a hard time.

/Alexandre

Hello,

Thanks very much Alexandre for your reply.

I am not expert in C++ and this is my first complex project with TouchGFX.

Anyway, yesterday evening , with the help of a friend, I managed to update texts in the subitems with an approach a bit different from what you suggest.

The problem now is that the updated texts do not respect the position I assigned to them. The texts are shown in subitems'textareas different from what I designed.

They also change when I switch from an item to another.

I'll try and make myself more clear. 

I have two items in a scrolllist "Scrolllist" each is a box which covers the entire screen (similar to what happens with Swipecontainer).

In each item there is a textarea "TextArea" which I update with no problems using a char text[2][10] variable and a method item.mymethod(itemIndex, text, ...), within the ScrolllistUpdatItem(....) method called in the Screeview file and defined in the SCROLLITEM.hpp .

In each aforementioned items there is also another scrolllist: So I have: "SubScrolllist" #0 and SubScrolllist" #1.

Each of these scrolllists has a variable number of (sub)items/boxes (for example: 2 and 3) each with a textarea "SubTextArea".

In order to update the number of subitems and the textareas I use a int16_t numsubItem[2] and a char subtext[2][3][10] variables

and then I modified item.mymethod(itemIndex,...) inserting, besides new variables, a Switch structure:

------------------------------------

ScreenView.hpp

char text[2][10]={"text1", "text2"};
 
 int16_t numsubItem[2]={2, 3};
char subtext[2][3][10]={{"subtext1-1", "subtext1-2"}, {"subtext2-1", "subtext2-2", "subtext2-3"}};
char tempsubtext[3][10];
 
...
 
void ScreenView::setupScreen()
{
 ScreenViewBase::setupScreen();
 Scrollist.setNumberOfItems(2);
}
 
...  
 
/*I didn't inserted any 
void MainView::handleClickEvent(const ClickEvent& evt)
void MainView::handleDragEvent(const DragEvent& evt)
or
void MainView::handleTickEvent()
because I didn't think I needed them for my design but I may be wrong
*/
 
void ScreenView::ScrollistUpdateItem(SCROLLITEM& item, int16_t itemIndex)
{
	Unicode::UnicodeChar utext[9];
	item.mymethod(itemIndex, text, utext, numsubItem, subtext, tempsubtext);
}

------------------------

SCROLLITEM.hpp

...
 
void mymethod(int16_t no, char dummytext[2][10], Unicode::UnicodeChar udummytext, int16_t dummynsubItem[2], char dummysubtext[2][3][10], char dummytempsubtext[3][10])
{
  Unicode::fromUTF8((const uint8_t *) dummytext[no], udummytext, 10);
  Unicode::snprintf(TextAreaBuffer, 10, "%s", udummytext);
  TextArea.invalidate();
switch (no)
  {
  case 0:
  	SubScrolllist.setNumberOfItems(dummynsubItem[0]);
  	for (int j=0; j<dummynsubItem[0]; j++)
  	{
  		for(int i=0; i<10; i++)
  		{
  			dummytempsubtext[j][i]='\0';
  		}
 		for(int i=0; dummysubtext[0][j][i]!='\0'; i++)
  		{
  			dummytempsubtext[j][i]= dummysubtext[0][j][i];
  		}
  	}
  	break;
  case 1:
  	SubScrolllist.setNumberOfItems(numsubItem[1]);
  	for(int j=0; j<numsubItem[1]; j++)
  	{
  		for(int i=0; i<10; i++)
  		{
  			dummytempsubtext[j][i]='\0';
  		}
 
  		for(int i=0; dummysubtext[1][j][i]!='\0'; i++)
  		{
  			dummytempsubtext[j][i]= dummysubtext[0][j][i];
  		}
  	}
  	break;
  }
  SubScrolllist.invalidate();
}
 
virtual void SubScrolllistUpdateItem(SUBITEM& item, int16_t itemIndex);
...

------------------

this last method is implemented in SCROLLITEM.cpp as follows:

SCROLLITEM.cpp

extern char tempsubtext[3][10];
...
void Scrolllist::SubScrolllistUpdateItem(SUBITEM& item, int16_t itemIndex)
{
	Unicode::UnicodeChar utempsubtext[9];
	item.mymethodSubItem(itemIndex, tempsubtext, utempsubtext);
}

--------------------------------------

where the last method is implemented in SUBITEM.cpp as follows:

SUBITEM.hpp

....
 
 void mymethodSubItem(int16_t no, char dummytempsubtext[3][10], Unicode::UnicodeChar utempsubtext[9])
 {
  Unicode::fromUTF8((const uint8_t *) dummytempsubtext[no], udummytempsubtext, 10);
  Unicode::snprintf(SubTextAreaBuffer, 10, "%s", udummytempsubtext);
  SubTextAreaBuffer.invalidate();
 }

I cannot explain my situation better than this. I simplified my code for a better understanding (I hope).

Probably I designed wrongly the subitems management and maybe there is a better way to do what I want to do.

I tried debugging but I cannot figure out the problem.

I hope someone can help.

Thanks

Have a good day

Pietro