0

I am using spinner in android action bar and want to display some items.But that spinner background has image.When I add list of item in spinner.By default first value displays near to the image.Is there any way to remove that by default text.

My spinner code is :

    <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:background="@drawable/ic_action_overflow"
            android:entries="@array/spinnerItems"/>

array/spinnerItems :

    <string-array name="spinnerItems">
        <item>item1</item>
        <item>item2</item>
        <item>item3</item>
        <item>item4</item>
    </string-array>

Please find the attached image for reference :

enter image description here

I want to remove the text "item1" displayed near to action overflow image icon.

vimal mishra
  • 1,087
  • 2
  • 12
  • 32

2 Answers2

2
     ArrayAdapter<CharSequence> adapter =new ArrayAdapter<CharSequence>
      (this,android.R.layout.simple_spinner_item){
        @NonNull
        @Override
        public View getView(int position, @Nullable View convertView, 
      @NonNull ViewGroup parent) {
            // this part is needed for hiding the original view
            View view = super.getView(position, convertView, parent);
            view.setVisibility(View.GONE);
            return view;
        }
    };
yousef
  • 1,345
  • 1
  • 12
  • 20
  • you must create custom adapter extend array adapter you can see this answer create custom adapter https://stackoverflow.com/questions/35983176/how-to-create-spinner-list-using-customadapter-in-android – yousef Mar 01 '20 at 08:14
0

In layout XML for Spinner use android:prompt=""

 <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:prompt="@string/prompt"
            android:background="@drawable/ic_action_overflow"
            android:entries="@array/spinnerItems"/>

Or

add first item of spinner like

<item>""</item>

and promt string also should be

 <item>""</item>
Android Geek
  • 8,956
  • 2
  • 21
  • 35