title: How to create filter icon in ActionBar Toolbar programatically
body: <p>I just Need to create a tool bar like this
  <a href="https://i.stack.imgur.com/1pREj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1pREj.png" alt="Example"></a></p>
  
  <p>Have a filter icon but I want dynamically add items taken from data base as if I Click item it will be sorted in this menu fliter icon 
  I hope that's gonna be clear
  here's my menu xml code</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt;
  
      &lt;item
          android:id="@+id/menu_spinner"
          android:actionViewClass="android.widget.Spinner"
          android:visible="false"
          android:showAsAction="always"/&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p>and this my MainActivity</p>
  
  <pre><code>package abtech.waiteriano.com.actionbartest;
  
  import android.app.ActionBar;
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.Spinner;
  
  public class MainActivity extends Activity {
  
      private MenuItem mSpinnerItem = null;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
      @Override
      public boolean onCreateOptionsMenu( Menu menu )
      {
          mSpinnerItem = menu.findItem( R.id.menu_spinner );
          getMenuInflater().inflate( R.menu.main, menu );
          mSpinnerItem = menu.findItem( R.id.menu_spinner );
          setupSpinner( mSpinnerItem );
          return true;
      }
      private void setupSpinner( MenuItem item )
      {
          item.setVisible( getActionBar().getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST );
          View view = item.getActionView();
          if (view instanceof Spinner)
          {
              Spinner spinner = (Spinner) view;
              spinner.setAdapter( ArrayAdapter.createFromResource( this,
                      R.array.spinner_data,
                      android.R.layout.simple_spinner_dropdown_item ) );
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0K96M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0K96M.png" alt="Error"></a></p>