I like to change my spinners typeface to "monospace".
Right now I'm populating my spinner this way:
resourceId = this.getResources().getIdentifier(country+"_umsatzsteuer_view", "array", this.getPackageName());
resourceId2 = this.getResources().getIdentifier(country+"_umsatzsteuer_werte", "array", this.getPackageName());
final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, resourceId, android.R.layout.simple_spinner_item );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
spinner_steuer = (Spinner) findViewById(R.id.spinner_steuer);
spinner_steuer.setAdapter(adapter);
My question is, how I can set the typeface of every item from this spinner to "monospace"?
UPDATED CODE:
Adaptercode:
public class YourItemAdapter extends ArrayAdapter<String> {
public YourItemAdapter(Context _context, int _resource,
List<String> _items) {
super(_context, _resource, _items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
//You can use the new tf here.
View v =super.getDropDownView(position, convertView, parent);
((TextView) v).setTypeface(Typeface.MONOSPACE, Typeface.BOLD);
return v;
}
}
Spinnerloading:
final ArrayAdapter<CharSequence> adapter = YourItemAdapter.createFromResource(
this, resourceId, android.R.layout.simple_spinner_item );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
spinner_steuer = (Spinner) findViewById(R.id.spinner_steuer);
spinner_steuer.setAdapter(adapter);
Thanks in advance! MSeiz5
I solved the problem by myself! I have created a custom adapter and a custom spinner.
Code (JAVA) - (Mainsite.java)
XML: (spinner_steuer_row.xml)