listview - Overriding Android ArrayAdapter -


i want simple thing. have listview in application dynamically add text to. but, after point, change color of text inside listview. so, made xml defining custom list item, , subclassed arrayadapter. but, whenever call add() method on custom arrayadapter, item added listview, text not placed it.

here's xml: `

<textview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_content" android:textsize="8pt"     android:gravity="center" android:layout_margin="4dip"     android:layout_width="fill_parent" android:layout_height="wrap_content" android:textcolor="#ff00ff00"/> 

and arrayadapter subclass:

private class customadapter extends arrayadapter<string> {     public view v;     public customadapter(context context){           super(context, r.layout.gamelistitem);     }      @override     public view getview(int pos, view convertview, viewgroup parent){         this.v = convertview;         if(v==null) {             layoutinflater vi = (layoutinflater)getsystemservice(context.layout_inflater_service);             v=vi.inflate(r.layout.gamelistitem, null);         }          if(timeleft!=0) {             textview tv = (textview)v.findviewbyid(r.id.list_content);             //tv.settext(str[pos]);             tv.settextcolor(color.green);         }         else {             textview tv = (textview)v.findviewbyid(r.id.list_content);             //tv.settext(str[pos]);             tv.settextcolor(color.red);         }          return v;     } } 

i'm sure i'm doing horribly wrong, i'm still little new android.

thank you! `

you need set text in getview(). value set getitem(pos), set it.

public view getview(int pos, view convertview, viewgroup parent){     this.v = convertview;     if(v==null) {         layoutinflater vi = (layoutinflater)getsystemservice(context.layout_inflater_service);         v=vi.inflate(r.layout.gamelistitem, null);     }      // moved outside if blocks, because need regardless     // of value of timeleft.     textview tv = (textview)v.findviewbyid(r.id.list_content);     tv.settext(getitem(pos));      if(timeleft!=0) {         //textview tv = (textview)v.findviewbyid(r.id.list_content);         //tv.settext(str[pos]);         tv.settextcolor(color.green);     }     else {         //textview tv = (textview)v.findviewbyid(r.id.list_content);         //tv.settext(str[pos]);         tv.settextcolor(color.red);     }      return v; } 

also, there reason you're storing v member variable, rather inside function?


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -