Skip to main content
February 29, 2020
Question

Updating elements of ScrollList

  • February 29, 2020
  • 7 replies
  • 1152 views

Hello! I create CustomContainer1, added to it textArea1 with wildcard buffer

I added CustomContainer1 to ScrollList2 and compiled project

I added button1 and want to change item №2 in CustomContainer1 by clicking button1

I added Iteraction to button1 - clicking is calling ChangeItemName() function.

In CustomContainer1.cpp :

void CustomContainer1::SetItemName(uint16_t data)
{
 Unicode::snprintf(textArea1Buffer, 20, "%d", data);
		textArea1.setWildcard(textArea1Buffer);
	textArea1.resizeToCurrentText(); 
	 textArea1.invalidate();
}

In Screen1View.cpp:

void Screen1View::scrollList2UpdateItem(CustomContainer1& item, int16_t itemIndex)
{
 uint16_t item_name_value;
 
 item_name_value=itemIndex;
 item.SetItemName(item_name_value);
 }
void Screen1View::ChangeItemName(uint16_t number)
{
??????????????????????????????
}

 What I have to add to ChangeItemName() if I want to change some Item of ScrollList ?

CustomContainer1.SetItemName(1); - error

This topic has been closed for replies.

7 replies

March 1, 2020

I found solution!!

	(*(CustomContainer1*)scrollList1ListItems.getDrawable(ItemNumber)).SetItemName(ItemName);

March 1, 2020

Still have problem

uint8_t str[] = "FileName"; 
		Unicode::snprintf(textArea1Buffer, 20, "%s", str);
		textArea1.setWildcard(textArea1Buffer);
	 textArea1.resizeToCurrentText(); 

Can't write any text.

uint8_t str[] = "FileName"; 
uint16_t data;
		Unicode::snprintf(textArea1Buffer, 20, "%d", data);
		textArea1.setWildcard(textArea1Buffer);
	 textArea1.resizeToCurrentText(); 

output digits.

How to write text?

PBull
Associate II
March 1, 2020

Hi,

try this:

	const char str[] = "FileName";
	Unicode::strncpy(textArea1Buffer, str, 20);
	textArea1.setWildcard(textArea1Buffer);
	textArea1.resizeToCurrentText();

Best regards,

Peter

March 1, 2020

Thanks!!!

Your code works!!!!

March 1, 2020

Solved!

I didn't set wildcard range.

But.... still have problem

Unicode::snprintf(textArea1Buffer, 20, "%s","RB

prints "B".

Unicode::snprintf(textArea1Buffer, 20, "%s","RBJ");

prints "?J?"

Only last character and "?"

Why?

PBull
Associate II
March 1, 2020

Hi,

your code doesn't work because %s needs a zero-terminated UnicodeChar list, but you passed a const char ("RBJ").

You have to copy your string to a UnicodeChar list and pass your UnicodeChar buffer to snprintf:

	Unicode::UnicodeChar buffer[20];
	const char str[] = "RBJ";
	Unicode::strncpy(buffer, str, 20);
	Unicode::snprintf(textArea1Buffer, 20, "%s", buffer);
	textArea1.resizeToCurrentText();

March 1, 2020

Good! It works!!!

Thanks!