Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:10:03+00:00 2026-06-11T05:10:03+00:00

I’m trying to accomblish the following task: A ListView, with textview rows When I

  • 0

I’m trying to accomblish the following task:

  • A ListView, with textview rows
  • When I click on an item, the text changes to italic

The change to italic can be something else – the point is to change the text in some way.

I thought to use Html.fromHtml, since that’s pretty easy to deal with when formatting text. However, I cannot get it to work accross my design.

In my main activity, I create and access the ListView and ArrayAdapter like this:

lv = (ListView) this.findViewById(R.id.itemslist);

I have a method for creating/updating the adapter, so that I can update the contents of the list:

private void displayList () {
   adapter = new ItemArrayAdapter(getApplicationContext(), R.layout.item_listitem, items);
    lv.setAdapter(adapter);
    adapter.setNotifyOnChange(true);

}

My OnItemClickListener:

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Toast.makeText(ShoppingListApp02Activity.this, "List item selected:" + 
        items.get(position).getId(), Toast.LENGTH_LONG).show();
    items.get(position).setName("<i>" + items.get(position).getName() + "</i>");
    displayList();
});

As you can see, on select/click of an item, I send the item’s name surrounded by the html tags, to the Item class’ setName() method. The name (type String) of the item object is now “<i>name</i>”

The setName() method in the Item class:

public void setName (String nname) { this.name = nname; }

Now, in the ArrayAdapter class (ItemArrayAdaper.java), the name is set in the TextView row of the ListView:

itemName.setText(item.name);

If I leave the code above as it is, when clicking the item in the list, the name changes to this: “<i>name</i>.

So far, it’s as I expected.

However, from there I need to convert the string “<i>name</i> to the html result, namely “name“. But when I try that like this:

itemName.setText(Html.fromHtml(item.name).toString());

it simply skips the html tags and displays the name string normally.

Why isn’t the fromHtml working here?

To compare, I tried just setting the contents of another TextView in my application (the footer) in the same way, with just:

footerview.setText(Html.fromHtml("<i><font color='#123456'>text</font></i>"));

And that worked just fine. But somewhere along the path, the tags surrounding the item name is lost. And that’s strange, because in the ItemArrayAdapter class when I don’t try to convert from html, the tags are there. They just aren’t honored when using the fromHtml method at the same place.

Any ideas?

And, I know there’s probably a better way to do this, and I’d be interested in that too 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:10:05+00:00Added an answer on June 11, 2026 at 5:10 am

    Easy solution: Remove the toString(). I didn’t try that because I had problems with it before, thinking that the data passed to a TextView HAS to be a pure string. However, it works like a charm without the toString() 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.