Skip to main content
Feb 29, 2020 5:48 PM UTC
Question

Updating elements of ScrollList

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

Mar 1, 2020 9:47 AM UTC

I found solution!!

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

Mar 1, 2020 11:30 AM UTC

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
Mar 1, 2020 1:56 PM UTC

Hi,

try this:

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

Best regards,

Peter

Mar 1, 2020 2:07 PM UTC

Thanks!!!

Your code works!!!!

Mar 1, 2020 1:39 PM UTC

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
Mar 1, 2020 2:37 PM UTC

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();

Mar 1, 2020 2:52 PM UTC

Good! It works!!!

Thanks!