我想为ListView创建一个CustomItem,我的String文本有问题。我尝试放置一个字符串为“\ n”的字符串进行换行。
我像这样创建我的字符串:
String fullName ="First Name: ";
fullName.Append(firstName);//one string variable
fullName.Append("\n");
fullName.Append("Last Name: ");
fullName.Append(lastName);//one string variable
我希望lastName和FirstName出现在不同的行中。
我把这个字符串放在我的自定义项目中: pCitem->的addElement(OSP ::图形::矩形(10,-30,430,150),索引,全名,35,OSP ::图形::颜色:: COLOR_GREEN,OSP ::图形::颜色:: COLOR_RED,真) ;
我的问题是firstName和lastName没有显示在不同的行中。我怎么解决这个问题?感谢
答案 0 :(得分:1)
您使用的 AddElement()方法仅允许您插入单行字符串。 对于多行字符串,您必须创建一个支持文本的 EnrichedText 多行并使用:
result CustomItem::AddElement (const Osp::Graphics::Rectangle &rect,
int elementId,
const Osp::Graphics::EnrichedText &text)
将其插入 CustomItem 。
的方法希望这有帮助!
答案 1 :(得分:0)
您可以添加两个字符串,一个带有名字,另一个带有姓氏,如下所示。其中 Rectangle()函数包含不同的坐标。
String firstName(L"First Name: ");
firstName.Append("first name");
String lastName(L"Last Name: ");
lastName.Append("last name");
pCitem->AddElement(Rectangle(10,30,430,150),index,firstName,35,Osp::Graphics::Color::COLOR_GREEN,Osp::Graphics::Color::COLOR_RED,true);
pCitem->AddElement(Rectangle(10,65,430,150),index,lastName,35,Osp::Graphics::Color::COLOR_GREEN,Osp::Graphics::Color::COLOR_RED,true);