Android change text color of items in spinner?

I figured out that to make this work you have to override the getDropDownView when setting up the ArrayAdapter in the main activity public class main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); setContentView(R.layout. Main); PatchedSpinner pSpinner = (PatchedSpinner) findViewById(R.id.

Spinner2); ArrayList testarray = new ArrayList(); testarray. Add("item0"); testarray. Add("item1"); testarray.

Add("item2"); testarray. Add("item3"); ArrayAdapter spinnerAdapter = new ArrayAdapter (this,android.R.layout. Simple_spinner_dropdown_item, testarray){ public boolean isEnabled(int position) { if(position == 1){ return false; }else{ return true; } } public boolean areAllItemsEnabled() { return false; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent){ View v = convertView; if (v == null) { Context mContext = this.getContext(); LayoutInflater vi = (LayoutInflater) mContext.

GetSystemService(Context. LAYOUT_INFLATER_SERVICE); v = vi. Inflate(R.layout.

Row, null); } TextView tv=(TextView) v. FindViewById(R.id. SpinnerTarget); tv.

SetText(testarray. Get(position)); switch (position) { case 0: tv. SetTextColor(Color.

RED); break; case 1: tv. SetTextColor(Color. BLUE); break; default: tv.

SetTextColor(Color. BLACK); break; } return v; } }; pSpinner. SetAdapter(spinnerAdapter); } The layout that is being inflated is a custom layout called row.xml.It is used to set the display for the dropdown view?

Xml version="1.0" encoding="utf-8"?

I figured out that to make this work you have to override the getDropDownView when setting up the ArrayAdapter in the main activity. Public class main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); setContentView(R.layout.

Main); PatchedSpinner pSpinner = (PatchedSpinner) findViewById(R.id. Spinner2); ArrayList testarray = new ArrayList(); testarray. Add("item0"); testarray.

Add("item1"); testarray. Add("item2"); testarray. Add("item3"); ArrayAdapter spinnerAdapter = new ArrayAdapter (this,android.R.layout.

Simple_spinner_dropdown_item, testarray){ public boolean isEnabled(int position) { if(position == 1){ return false; }else{ return true; } } public boolean areAllItemsEnabled() { return false; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent){ View v = convertView; if (v == null) { Context mContext = this.getContext(); LayoutInflater vi = (LayoutInflater) mContext. GetSystemService(Context. LAYOUT_INFLATER_SERVICE); v = vi.

Inflate(R.layout. Row, null); } TextView tv=(TextView) v. FindViewById(R.id.

SpinnerTarget); tv. SetText(testarray. Get(position)); switch (position) { case 0: tv.

SetTextColor(Color. RED); break; case 1: tv. SetTextColor(Color.

BLUE); break; default: tv. SetTextColor(Color. BLACK); break; } return v; } }; pSpinner.

SetAdapter(spinnerAdapter); } The layout that is being inflated is a custom layout called row.xml. It is used to set the display for the dropdown view.

Check this link You can set the font color in getCustomView method.

When I try to use the getCustomView method I get this error. "The method getLayoutInflater() is undefined for the type PatchedSpinner. DropDownAdapter" any ideas – Jonathan Apr 29 at 21:01.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions