3

I am developing an app where i need to use some maths special characters in it. After a long search in google i found the following solution i.e.., How to put some special math symbols in TextView, EditView or other Android UI element. As per the above link if i am using textview means it is working good. But how to use the following "HTML.frommHtml()" in listview. I tried but it is getting error......

code: (using Textview)

//by using textview

  String htmlStringWithMathSymbols = " ∂   ∆   ∏   ∑      =   ≠   ≈   ≡";
  txtv.setText(Html.fromHtml(htmlStringWithMathSymbols));

How to use the following "HTML.frommHtml()" with listview. when i am adding same code for listview it is getting error...

code: (using ListView)

//by using listview

 String[] andi={"andi 4","andi 5" , "∂" , "∆","∏"};    

ArrayAdapter<String> adp = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, andi);
    lv.setAdapter(Html.fromHtml(adp));

While using with listview in the place of "fromHtml()" it is showing error as "The method fromHtml(String) in the type Html is not applicable for the arguments (ArrayAdapter)".

So how can i use the following "Html.fromHtml()" code with listview or spinner....

code_finder
  • 1,370
  • 2
  • 21
  • 39

1 Answers1

5

try this :

CharSequence[] andi={Html.fromHtml("andi 4"), Html.fromHtml("andi 5") , Html.fromHtml("&#8706;") , Html.fromHtml("&#8710;"),Html.fromHtml("&#8719;")};    

    ArrayAdapter<CharSequence> adp = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_list_item_1, andi);
    lv.setAdapter(adp);

in your code you try to set string value for adapter and passing the adapter to fromHtml function

sunil
  • 6,444
  • 1
  • 32
  • 44
  • That's a great code but in place of "String[]" need to take "CharSequence[]" because as per the the following code, array declared are not recognizing as array of strings because of "not using double quotes". It worked by using CharSequence[].... Thanks for your code... – code_finder Jul 30 '12 at 07:16
  • 1
    yes... you are right. just updated the answer :). thanks for pointing the mistake. – sunil Jul 30 '12 at 07:25