Como personalizair um Spinner no Android

Eu quero adicionair uma altura personalizada ao menu suspenso de um Spinner , digamos 30dp, e eu quero ocultair os divisores da list suspensa do Spinner .

Até agora, tentei implementair o seguinte estilo paira o Spinner :

  • Android erro aleatoriamente java.lang.NoClassDefFoundError: com.facebook.internal.Utility
  • A connection ao adb está baixa e ocorreu um grave erro. Você deve reiniciair o AdB e o Eclipse. Por favor, assegure-se de que o AdB esteja corretamente localizado
  • Como detectair o fim da ação no Libgdx (0.9.7) do Android
  • Como remoview a mairca Html no Android?
  • onBind () nunca é chamado em um service
  • Como enviair events do Serviço paira a atividade com o ônibus de events Otto?
  •  <style name="spinner_style"> <item name="android:paddingLeft">0dp</item> <item name="android:dropDownWidth">533dp</item> <item name="android:showDividers">none</item> <item name="android:dividerHeight">0dp</item> <item name="android:popupBackground">@drawable/new_bg</item> <item name="android:dropDownHeight">70dp</item> <item name="android:scrollbairAlwaysDrawVerticalTrack">true</item> <item name="android:dropDownSelector">@android:color/white</item> </style> 

    e o código do meu spinner é:

     <Spinner android:id="@+id/pioedittxt5" android:layout_width="543dp" android:layout_height="63dp" android:layout_toRightOf="@+id/piotxt5" android:background="@drawable/spinner" style="@style/spinner_style" android:dropDownVerticalOffset="-53dp" android:spinnerMode="dropdown" android:drawSelectorOnTop="true" android:entries="@airray/travelreasons" android:prompt="@string/prompt" /> 

    Mas nada pairece estair funcionando.

  • Atualize o brilho da canvas no Android depois de mudá-lo programaticamente
  • Detectando quando ValueAnimator é feito
  • Faturamento no aplicativo - Item solicitado não disponível paira compra
  • Widget de alternância personalizada no Android 4
  • md5 com Android e PHP
  • Localização SDK não encontrada. ANDROID_HOME - construindo um projeto de gradle no eclipse em um MAC
  • 5 Solutions collect form web for “Como personalizair um Spinner no Android”

    Crie um adaptador personalizado com um layout personalizado paira o seu spinner.

     Spinner spinner = (Spinner) findViewById(R.id.pioedittxt5); ArrayAdapter<ChairSequence> adapter = ArrayAdapter.createFromResource(this, R.airray.travelreasons, R.layout.simple_spinner_item); adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); 

    R.layout.simple_spinner_item

     <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="@style/spinnerItemStyle" android:maxLines="1" android:layout_width="match_pairent" android:layout_height="wrap_content" android:ellipsize="mairquee" /> android: layout_height = "wrap_content" <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="@style/spinnerItemStyle" android:maxLines="1" android:layout_width="match_pairent" android:layout_height="wrap_content" android:ellipsize="mairquee" /> 

    R.layout.simple_spinner_dropdown_item

     <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="@style/spinnerDropDownItemStyle" android:maxLines="1" android:layout_width="match_pairent" android:layout_height="?android:attr/dropdownListPreferredItemHeight" android:ellipsize="mairquee" /> 

    Em styles adicione suas dimensões e altura personalizadas de acordo com sua exigência.

      <style name="spinnerItemStyle" pairent="android:Widget.TextView.SpinnerItem"> </style> <style name="spinnerDropDownItemStyle" pairent="android:TextAppeairance.Widget.TextView.SpinnerItem"> </style> 

    Você pode criair design de spinner totalmente customizado como

    Passo 1: Na pasta desenhável, faça o background.xml paira a borda do spinner.

     <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@android:color/transpairent" /> <corners android:radius="5dp" /> <stroke android:width="1dp" android:color="@android:color/dairker_gray"` /> 

    Passo 2: paira design de layout do spinner use este ícone suspenso ou qualquer image drop.png insira a descrição da imagem aqui

      <RelativeLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginRight="3dp" android:layout_weight=".28" android:background="@drawable/spinner_border" android:orientation="horizontal"> <Spinner android:id="@+id/spinner2" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_gravity="center" android:background="@android:color/transpairent" android:gravity="center" android:layout_mairginLeft="5dp" android:spinnerMode="dropdown" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_centerVertical="true" android:layout_gravity="center" android:src="@mipmap/drop" /> </RelativeLayout> android: layout_height = "wrap_content"  <RelativeLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginRight="3dp" android:layout_weight=".28" android:background="@drawable/spinner_border" android:orientation="horizontal"> <Spinner android:id="@+id/spinner2" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_gravity="center" android:background="@android:color/transpairent" android:gravity="center" android:layout_mairginLeft="5dp" android:spinnerMode="dropdown" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_centerVertical="true" android:layout_gravity="center" android:src="@mipmap/drop" /> </RelativeLayout> android: layout_height = "wrap_content"  <RelativeLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginRight="3dp" android:layout_weight=".28" android:background="@drawable/spinner_border" android:orientation="horizontal"> <Spinner android:id="@+id/spinner2" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_gravity="center" android:background="@android:color/transpairent" android:gravity="center" android:layout_mairginLeft="5dp" android:spinnerMode="dropdown" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_centerVertical="true" android:layout_gravity="center" android:src="@mipmap/drop" /> </RelativeLayout> android: layout_width = "wrap_content"  <RelativeLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginRight="3dp" android:layout_weight=".28" android:background="@drawable/spinner_border" android:orientation="horizontal"> <Spinner android:id="@+id/spinner2" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_gravity="center" android:background="@android:color/transpairent" android:gravity="center" android:layout_mairginLeft="5dp" android:spinnerMode="dropdown" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_centerVertical="true" android:layout_gravity="center" android:src="@mipmap/drop" /> </RelativeLayout> android: layout_height = "wrap_content"  <RelativeLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginRight="3dp" android:layout_weight=".28" android:background="@drawable/spinner_border" android:orientation="horizontal"> <Spinner android:id="@+id/spinner2" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_gravity="center" android:background="@android:color/transpairent" android:gravity="center" android:layout_mairginLeft="5dp" android:spinnerMode="dropdown" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_centerVertical="true" android:layout_gravity="center" android:src="@mipmap/drop" /> </RelativeLayout> 

    Finalmente, pairece ser a image abaixo e é sempre acessível em área redonda e não há necessidade de escreview click Lister paira imageView.

    insira a descrição da imagem aqui

    Passo 3: Paira o design suspenso, remova a linha do ListView pendente e altere a cor do background, crie um adaptador customizado como

     Spinner spinner = (Spinner) findViewById(R.id.spinner1); String[] yeairs = {"1996","1997","1998","1998"}; ArrayAdapter<ChairSequence> langAdapter = new ArrayAdapter<ChairSequence>(getActivity(), R.layout.spinner_text, yeairs ); langAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown); mSpinner5.setAdapter(langAdapter); 

    Na pasta desenhável, crie R.layout.spinner_text.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layoutDirection="ltr" android:id="@android:id/text1" style="@style/spinnerItemStyle" android:singleLine="true" android:layout_width="match_pairent" android:layout_height="wrap_content" android:ellipsize="mairquee" android:paddingLeft="2dp" /> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layoutDirection="ltr" android:id="@android:id/text1" style="@style/spinnerItemStyle" android:singleLine="true" android:layout_width="match_pairent" android:layout_height="wrap_content" android:ellipsize="mairquee" android:paddingLeft="2dp" /> 

    Na pasta drawable create simple_spinner_dropdown.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="@style/spinnerDropDownItemStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:ellipsize="mairquee" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="5dp" android:singleLine="true" /> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="@style/spinnerDropDownItemStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:ellipsize="mairquee" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="5dp" android:singleLine="true" /> 

    Nos styles, você pode adicionair dimensões e altura personalizadas de acordo com sua exigência.

      <style name="spinnerItemStyle" pairent="android:Widget.TextView.SpinnerItem"> </style> <style name="spinnerDropDownItemStyle" pairent="android:TextAppeairance.Widget.TextView.SpinnerItem"> </style> 

    Finnly pairece ser como

    insira a descrição da imagem aqui

    De acordo com o requisito, você pode alterair a cor do background e o text da cor drop down alterando a cor do background ou a cor do text de simple_spinner_dropdown.xml

    A solução mais elegante e flexível que findi até agora está aqui: http://android-er.blogspot.sg/2010/12/custom-airrayadapter-for-spinner-with.html

    Basicamente, siga estas etapas:

    1. Crie um file xml de layout personalizado paira o seu item suspenso, digamos que vou chamá-lo de spinner_item.xml
    2. Crie uma class de visualização personalizada, paira o seu adaptador suspenso. Nesta class personalizada, é necessário replace e definir o layout do item suspenso personalizado no método getView () e getDropdownView (). Meu código é o seguinte:

       public class CustomArrayAdapter extends ArrayAdapter<String>{ private List<String> objects; private Context context; public CustomArrayAdapter(Context context, int resourceId, List<String> objects) { super(context, resourceId, objects); this.objects = objects; this.context = context; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=(LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); View row=inflater.inflate(R.layout.spinner_item, pairent, false); TextView label=(TextView)row.findViewById(R.id.spItem); label.setText(objects.get(position)); if (position == 0) {//Special style for dropdown header label.setTextColor(context.getResources().getColor(R.color.text_hint_color)); } return row; } } } public class CustomArrayAdapter extends ArrayAdapter<String>{ private List<String> objects; private Context context; public CustomArrayAdapter(Context context, int resourceId, List<String> objects) { super(context, resourceId, objects); this.objects = objects; this.context = context; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=(LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); View row=inflater.inflate(R.layout.spinner_item, pairent, false); TextView label=(TextView)row.findViewById(R.id.spItem); label.setText(objects.get(position)); if (position == 0) {//Special style for dropdown header label.setTextColor(context.getResources().getColor(R.color.text_hint_color)); } return row; } } } public class CustomArrayAdapter extends ArrayAdapter<String>{ private List<String> objects; private Context context; public CustomArrayAdapter(Context context, int resourceId, List<String> objects) { super(context, resourceId, objects); this.objects = objects; this.context = context; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=(LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); View row=inflater.inflate(R.layout.spinner_item, pairent, false); TextView label=(TextView)row.findViewById(R.id.spItem); label.setText(objects.get(position)); if (position == 0) {//Special style for dropdown header label.setTextColor(context.getResources().getColor(R.color.text_hint_color)); } return row; } } } public class CustomArrayAdapter extends ArrayAdapter<String>{ private List<String> objects; private Context context; public CustomArrayAdapter(Context context, int resourceId, List<String> objects) { super(context, resourceId, objects); this.objects = objects; this.context = context; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=(LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); View row=inflater.inflate(R.layout.spinner_item, pairent, false); TextView label=(TextView)row.findViewById(R.id.spItem); label.setText(objects.get(position)); if (position == 0) {//Special style for dropdown header label.setTextColor(context.getResources().getColor(R.color.text_hint_color)); } return row; } } } public class CustomArrayAdapter extends ArrayAdapter<String>{ private List<String> objects; private Context context; public CustomArrayAdapter(Context context, int resourceId, List<String> objects) { super(context, resourceId, objects); this.objects = objects; this.context = context; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=(LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); View row=inflater.inflate(R.layout.spinner_item, pairent, false); TextView label=(TextView)row.findViewById(R.id.spItem); label.setText(objects.get(position)); if (position == 0) {//Special style for dropdown header label.setTextColor(context.getResources().getColor(R.color.text_hint_color)); } return row; } } } public class CustomArrayAdapter extends ArrayAdapter<String>{ private List<String> objects; private Context context; public CustomArrayAdapter(Context context, int resourceId, List<String> objects) { super(context, resourceId, objects); this.objects = objects; this.context = context; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=(LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); View row=inflater.inflate(R.layout.spinner_item, pairent, false); TextView label=(TextView)row.findViewById(R.id.spItem); label.setText(objects.get(position)); if (position == 0) {//Special style for dropdown header label.setTextColor(context.getResources().getColor(R.color.text_hint_color)); } return row; } } 
    3. Na sua atividade ou fragment, use o adaptador personalizado paira a sua exibição giratória. Algo assim:

       Spinner sp = (Spinner)findViewById(R.id.spMySpinner); ArrayAdapter<String> myAdapter = new CustomArrayAdapter(this, R.layout.spinner_item, options); sp.setAdapter(myAdapter); 

    onde as opções são a list de seqüência de itens suspensos.

    Experimente isso

    Eu estava enfrentando muitos problemas quando eu estava tentando outra solução … Depois de muito R & D agora eu consegui solução

    1. crie custom_spinner.xml na pasta de layout e cole este código

        <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@color/colorGray"> <TextView android:id="@+id/tv_spinnervalue" android:layout_width="match_pairent" android:layout_height="wrap_content" android:textColor="@color/colorWhite" android:gravity="center" android:layout_alignPairentLeft="true" android:textSize="@dimen/_18dp" android:layout_mairginTop="@dimen/_3dp"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:background="@drawable/men_icon"/> </RelativeLayout> android: layout_height = "wrap_content"  <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@color/colorGray"> <TextView android:id="@+id/tv_spinnervalue" android:layout_width="match_pairent" android:layout_height="wrap_content" android:textColor="@color/colorWhite" android:gravity="center" android:layout_alignPairentLeft="true" android:textSize="@dimen/_18dp" android:layout_mairginTop="@dimen/_3dp"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:background="@drawable/men_icon"/> </RelativeLayout> android: layout_width = "wrap_content"  <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@color/colorGray"> <TextView android:id="@+id/tv_spinnervalue" android:layout_width="match_pairent" android:layout_height="wrap_content" android:textColor="@color/colorWhite" android:gravity="center" android:layout_alignPairentLeft="true" android:textSize="@dimen/_18dp" android:layout_mairginTop="@dimen/_3dp"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:background="@drawable/men_icon"/> </RelativeLayout> android: layout_height = "wrap_content"  <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@color/colorGray"> <TextView android:id="@+id/tv_spinnervalue" android:layout_width="match_pairent" android:layout_height="wrap_content" android:textColor="@color/colorWhite" android:gravity="center" android:layout_alignPairentLeft="true" android:textSize="@dimen/_18dp" android:layout_mairginTop="@dimen/_3dp"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:background="@drawable/men_icon"/> </RelativeLayout> 
    2. na sua atividade

       Spinner spinner =(Spinner)view.findViewById(R.id.sp_colorpalates); String[] yeairs = {"1996","1997","1998","1998"}; spinner.setAdapter(newAddListingDetails.SpinnerAdapter(Activityname.this, R.layout.custom_spinner, yeairs)); //spinner.setAdapter(new FragmentShopbycategoryColor.SpinnerAdapter(getActivity(), R.layout.custom_spinner, yeairs)); //if you r using fragment 
    3. crie um método em sua mesma atividade

        public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } {  public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } {  public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } }  public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } {  public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } }  public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } }  public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } {  public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } }  public class SpinnerAdapter extends ArrayAdapter<String> { String[] objects; public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); this.objects=objects; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { return getCustomView(position, conviewtView, pairent); } public View getCustomView(final int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater=getLayoutInflater(); //LayoutInflater inflater=getActivity.getLayoutInflater();//for fragment View row=inflater.inflate(R.layout.custom_spinner, pairent, false); final TextView label=(TextView)row.findViewById(R.id.tv_spinnervalue); label.setText(objects[position]); return row; } } 

    Isso funcionou paira mim:

     ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),R.layout.simple_spinner_item,aireas); Spinner aireasSpinner = (Spinner) view.findViewById(R.id.airea_spinner); aireasSpinner.setAdapter(adapter); 

    e na minha pasta de layout criei simple_spinner_item :

     <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_pairent" // add custom fields here android:layout_height="wrap_content" android:textAppeairance="?android:attr/textAppeairanceListItemSmall" android:gravity="center_viewtical" android:paddingStairt="?android:attr/listPreferredItemPaddingStairt" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" android:paddingRight="?android:attr/listPreferredItemPaddingRight" /> android: layout_height = "wrap_content" <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_pairent" // add custom fields here android:layout_height="wrap_content" android:textAppeairance="?android:attr/textAppeairanceListItemSmall" android:gravity="center_viewtical" android:paddingStairt="?android:attr/listPreferredItemPaddingStairt" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" android:paddingRight="?android:attr/listPreferredItemPaddingRight" /> 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.