0

I created a ListView program such that when a list item is clicked, it will open into a NewActivity. Now, i have made a string array to populate the ListView. The texts i want to display in the NewActivity has both italics and bold characters well formatted. I have converted the texts into HTML My question is; How can display this HTML texts in item array form. For Instance: HTML-Text-Here I have tried CDATA but there's no way i can fix it inside the code in the string.

This is what i tried that didn't work:

<item>"<![CDATA[ <p><span style="color: #ff0000;"><strong>The Love Pillar</strong></span></p>
<p>I Believe in love, the love of pure heart, sent..</p> ]]>"</item>

Here is my String.xml

<resources>

<string-array name="DescriptionLyrics">
        <item>
</item>
        <item>No.1 LyricsHere</item>
        <item>No.2 LyricsHere</item>
        <item>No.3 LyricsHere</item>
        <item>No.4 LyricsHere</item>
    </string-array>
    
    
    
    </resources>

3 Answers 3

1

I will categorize this solution in two stages.

Stage 1

Instantiate your TextView e.g TextView newTextView;

In your Activity.java, in the onCreate set

newTextView.setText(Html.fromHtml(getString(R.string.htmlFormattedText1aa)));

In Your String.xml set

<string name="htmlFormattedText1aa">"<![CDATA[ <p><span style="color: #ff0000;"><strong>The Love Pillar</strong></span></p>
<p>I Believe in love, the love of pure heart, sent..</p> ]]>"</string>

If you have TextView defined in your String; newTextView.setText(Html.fromHtml(getString(R.string.htmlFormattedText1aa)));

=====Stage 2=====

If you want to pass the array string items through Adapter

Instantiate your TextView e.g TextView newTextView;

Now, get data from previous activity when item of activity is clicked using intent

String newDescription = intent.getStringExtra("brandNewDesc");

I have already defined "brandNewDesc" in my ListViewAdapter and sent it to Activity.java using intent.putExtra("brandNewDesc", models.get(i).getBrandNewDesc());

Now in your Activity.java set mBrandNewDesc.setText(Html.fromHtml(newDescription));

Finally in the String.xml set thus;

 <item>"<![CDATA[ <p><font color="#ff0000"><b>The Love Pillar</b></font></p>
<p>I Believe in love, the love of pure heart, sent..</p> ]]>"</item>

Enjoy!!

Sign up to request clarification or add additional context in comments.

Comments

0

Simply use the code as

<item><p><font color="#ff0000"><b>The Love Pillar</b></font></p>
<p>I Believe in love, the love of pure heart, sent..</p></item>

Because! I already used this type of lists and paragraphs in my own project.

3 Comments

the texts appear as plain text. The color, bold character formats embedded didn't show. What do i do???
If i copy & paste the texts directly, the texts appear to be combined together without spaces and margin. Is there another way i can maintain the text markup style???
@Joseph You can use the static method in java class which returns Html.fromHtml("your html code"); and you can easily collect the required HTML content to use in TextView and other Views. Maybe, It helps - Have a great day :)
0

<item>"<![CDATA[ <p><span style="color: #ff0000;"><strong>The Love Pillar</strong></span></p>
<p>I Believe in love, the love of pure heart, sent..</p> ]]>"</item>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.