adapter - Control how to write to text to spinners and lists on Android -


i've written custom adapter few spinners , list views program. here code:

public static class customadapter extends arrayadapter<string> {      private int fontsize;     private int color;     private typeface typeface;     private int bgcolor = color.rgb(50, 50, 50);     private int selectedcolor = color.rgb(50, 50, 50);     private int selected = -1;      public customadapter(context context, int resource, typeface tf, int colour, int fsize) {         super(context, resource);         fontsize = fsize;         color = colour;         typeface = tf;     }      public void setbackgroundcolor(int bg){         bgcolor = bg;     }      public void setselectedcolor(int color){selectedcolor = color;}      public void setselectedpos(int p){         selected = p;         notifydatasetchanged();     }      public view getview(int position, view convertview, viewgroup parent) {         textview v = (textview)super.getview(position, convertview, parent);         v.settypeface(typeface);         v.settextsize(fontsize);         v.settextcolor(color);         if (position == selected) v.setbackgroundcolor(selectedcolor);         else v.setbackgroundcolor(bgcolor);         return v;     }       public view getdropdownview(int position,  view convertview,  viewgroup parent) {         textview v = (textview)super.getdropdownview(position, convertview, parent);         v.settypeface(typeface);         v.settextsize(fontsize);         v.settextcolor(color);         v.setbackgroundcolor(bgcolor);         return v;     }  } 

now want control how text set in text view return. more specific use spannablestring builder in other ordinary textviews of app. so:

    spannablestringbuilder textstring = new spannablestringbuilder();     aux.addtext(textstring,cardinfo,colors.white,dim.textsize_textview,fonts.normal);     text.settext(textstring, textview.buffertype.spannable); 

i write each item of adapter. can done? appreaciate if tell me how.

thought i'd answer own question, since found solution. key passed string list in constructor , return view , dropdown view corresponding text added spannable string builder. here custom adapter:

  public static class customadapter extends arrayadapter<string> {      private int fontsize;     private int color;     private typeface typeface;     private int bgcolor = color.rgb(50, 50, 50);     private int selectedcolor = color.rgb(50, 50, 50);     private int selected = -1;     private boolean setcolor = false;     private list<string> data;      public customadapter(context context, int resource, typeface tf, int colour, int fsize, list<string> labels) {         super(context, resource,labels);         fontsize = fsize;         color = colour;         typeface = tf;         data = labels;     }      public void setbackgroundcolor(int bg){         bgcolor = bg;         setcolor = true;     }      public void setselectedcolor(int color){         selectedcolor = color;         setcolor = true;     }      public void setselectedpos(int p){         selected = p;         notifydatasetchanged();     }      public view getview(int position, view convertview, viewgroup parent) {         textview v = (textview)super.getview(position, convertview, parent);         spannablestringbuilder texter = new spannablestringbuilder();         aux.addtext(texter,data.get(position),color,fontsize,typeface);         if (v != null) {             v.settext(texter, textview.buffertype.spannable);             if (setcolor) {                 if (position == selected) v.setbackgroundcolor(selectedcolor);                 else v.setbackgroundcolor(bgcolor);             }         }         return v;     }       public view getdropdownview(int position,  view convertview,  viewgroup parent) {         textview v = (textview)super.getdropdownview(position, convertview, parent);         spannablestringbuilder texter = new spannablestringbuilder();         aux.addtext(texter, data.get(position), color, fontsize, typeface);         if (v != null) {             v.settext(texter, textview.buffertype.spannable);             if (setcolor) {                 if (position == selected) v.setbackgroundcolor(selectedcolor);                 else v.setbackgroundcolor(bgcolor);             }         }         return v;     }  } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -