Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 19
Registered: ‎07-12-2012
My Device: 9700, Playbook 16GB, and Dev Alpha
Accepted Solution

Escaping \n (New Line) only prints it

Hi, I have simple problem here:

I have a ListView that when selected will push NavigationPane with a long description on it.

 

The long description is stored in dataModel which also contain title for the list.

 

The problem is the \n (New Line) inside the description is literally printed as "\n" and not making a new line.

 

I tried  typing "Hello\nWorld" inside TextArea.text and it does create new line.

 

So, what's the problem here? Any solution? Thanks

Contributor
Posts: 19
Registered: ‎07-12-2012
My Device: 9700, Playbook 16GB, and Dev Alpha

Re: Escaping \n (New Line) only prints it

Hi, I manage to find a way to solve this by literally add new line in the dataModel.

 

For example:

<root>
    <header title="Group 1" >
        <item title="Item 1" description="1. Hello
2. World
3. Bye!" />
    </header>

 This way, the code become messy. Is there any better solution?

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Escaping \n (New Line) only prints it

[ Edited ]

Hi,

'\n' resolves to single character with ASCII code 10.

\n in dataModel text is two characters and not the newline.
How do you create and populate the dataModel?

 

upd:

This code in XML should be equivalent to '\n' in C++ code but regular newlines will also stay:

&#10;

 

Another option is loading XML manually using QXmlStreamReader, replacing newlines with spaces and "\n"-s with newlines, then adding the data to GroupDataModel or ArrayDataModel. XmlDataModel is not very flexible and doesn't allow editing of it's data.

 


Andrey Fidrya, @zmeyc on twitter
Contributor
Posts: 19
Registered: ‎07-12-2012
My Device: 9700, Playbook 16GB, and Dev Alpha

Re: Escaping \n (New Line) only prints it

Thanks &#10; does work to replace new line

For now, the data model is still hard-coded. User will be able to add more list later.

 

By the way, is there easy way to create ordered list / numbering? I prefer doing it in QML than C++.

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Escaping \n (New Line) only prints it

I think ordered list can be implementing by creating a custom ListItemComponent with a Label inside. Bind the label's text to current item's index. It can be accessed as ListItem.indexInSection.

Please create different threads for each question. :smileyhappy:

Andrey Fidrya, @zmeyc on twitter
Contributor
Posts: 19
Registered: ‎07-12-2012
My Device: 9700, Playbook 16GB, and Dev Alpha

Re: Escaping \n (New Line) only prints it

Okay Thanks a lot :Clap: