Programmatically set typeface and textsize of Spinner

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Programmatically set typeface and textsize of Spinner

Postby mobiforms » Mon Sep 14, 2009 9:21 pm

For other items setTypeface and setTextSize are available, but not for
Spinner. I would like to have a mechanism that dynamically changes
the Spinner without using a fixed XML definition. I am trying to re-
program the default android.R.layout.simple_spinner_item and
android.R.layout.simple_spinner_dropdown_item containers. I have
tried the following code without success. Where am I going wrong?

class ComboBox extends Spinner {
private int listid;
private ArrayList<String> alist = new ArrayList<String>();
private TextView ssi;
private CheckedTextView ssdi;

public ComboBox (Context context,int listid) {
super(context);
this.listid = listid;
ArrayAdapter<String> ladapt = new ArrayAdapter<String>(context,
android.R.layout.simple_spinner_item, alist);
ladapt.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
setAdapter(ladapt);
ssi = (TextView)findViewById
(android.R.layout.simple_spinner_item);
ssdi = (CheckedTextView)findViewById
(android.R.layout.simple_spinner_dropdown_item);
}

public int getId() {
return listid;
}

public void addItem(String txt) {
alist.add(txt);
}

public void setTypeface(Typeface tf) {
ssi.setTypeface(tf);
ssdi.setTypeface(tf);
}

public void setTextColor(int colour) {
ssi.setTextColor(colour);
ssdi.setTextColor(colour);
}

public void setTextSize(int sz) {
ssi.setTextSize(sz);
ssdi.setTextSize(sz);
}
}
mobiforms
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Sep 14, 2009 9:11 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests