java - Add html tags to list view row text -


in app create listview , normal construction of string bellow :

   final listview listview = (listview) findviewbyid(r.id.listview); string[] values = new string[] { "one", "two", "three",     "four"};  

but want add html tag text appear on each row have refer text string bellow :

one.settext(html.fromhtml(getstring(r.string.one))); two.settext(html.fromhtml(getstring(r.string.two))); three.settext(html.fromhtml(getstring(r.string.three))); four.settext(html.fromhtml(getstring(r.string.four))); 

which mean text appear in list view row can can created :

  string[] values = new string[] { "one", "two", "three",     "four"};  

or refered string-arry bellow :

<string-array name="days">     <item>one</item>     <item>two</item>     <item>three</item>     <item>four</item>  </string-array> 

but not want , want retrive text string .xml customized html tag dont know write in class instead .

update:

as answerd bellow did way:

myarrayadapter:

public class myarrayadapter extends arrayadapter<string> { private final activity context; typeface tf; static class viewholder {     public textview text;     }  public myarrayadapter(activity context, string string) {     super(context, r.layout.list_item);     this.context = context;}  @override public view getview(int position, view convertview, viewgroup parent) {     tf=typeface.createfromasset(context.getassets(),"bfantezy.ttf");      view rowview = convertview;     if (rowview == null) {       layoutinflater inflater = context.getlayoutinflater();       rowview = inflater.inflate(r.layout.list_item, null);        int resourcetouse = r.string.day1;;     switch(position){       case 1:            resourcetouse = r.string.day1;           break;       case 2:            resourcetouse = r.string.day2;           break;                     case 3:            resourcetouse = r.string.day3;           break;       case 4:            resourcetouse = r.string.day4;                }       textview mtextview = (textview) rowview.findviewbyid(r.id.label);       mtextview.settypeface(tf);        mtextview.settext(html.fromhtml(context.getstring(resourcetouse)));}       return rowview;}} 

androidlistviewactivity:

public class androidlistviewactivity extends listactivity { private string resourcetouse;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);       setlistadapter(new myarrayadapter(this,resourcetouse));                         }              } 

it gave : java.lang.classnotfoundexception

logcat:

    java.lang.runtimeexception: unable instantiate activity componentinfo    {com.androidhive.androidlistview/com.androidhive.androidlistview.    androidlistviewactivity.java}:    java.lang.classnotfoundexception:       com.androidhive.androidlistview.androidlistviewactivity.java       in loader dalvik.system.pathclassloader[/data/app/com.androidhive.androidlistview-          1.apk] @ android.app.activitythread.performlaunchactivity(activitythread.java:1573) @ android.app.activitythread.handlelaunchactivity(activitythread.java:1667) @ android.app.activitythread.access$1500(activitythread.java:117) @ android.app.activitythread$h.handlemessage(activitythread.java:935) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:130) @ android.app.activitythread.main(activitythread.java:3687) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:507) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:867) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:625) @ dalvik.system.nativestart.main(native method)     caused by: java.lang.classnotfoundexception:              com.androidhive.androidlistview.androidlistviewactivity.      java in loader dalvik.system.pathclassloader      [/data/app/com.androidhive.androidlistview-1.apk]     @ dalvik.system.pathclassloader.findclass(pathclassloader.java:240) @ java.lang.classloader.loadclass(classloader.java:551) @ java.lang.classloader.loadclass(classloader.java:511) @ android.app.instrumentation.newactivity(instrumentation.java:1021) @ android.app.activitythread.performlaunchactivity(activitythread.java:1565) ... 11 more             there way , appreciated , 

override arrayadapter's getview method, textview associated item's position in listview, , set text string resource based on current position:

public view getview(int position, view convertview, viewgroup parent) { tf=typeface.createfromasset(context.getassets(),"bfantezy.ttf");  view rowview = convertview; if (rowview == null) {   layoutinflater inflater = context.getlayoutinflater();   rowview = inflater.inflate(r.layout.list_item, null); }   int resourcetouse = r.string.day1; switch(position){   case 1:        resourcetouse = r.string.day1;       break;   case 2:        resourcetouse = r.string.day2;       break;                 case 3:        resourcetouse = r.string.day3;       break;   case 4:        resourcetouse = r.string.day4;                          }    textview mtextview = (textview) rowview.findviewbyid(r.id.label);   mtextview.settypeface(tf);    mtextview.settext(html.fromhtml(context.getstring(resourcetouse)));    return rowview;   }  

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -