List of usage examples for android.widget SpinnerAdapter SpinnerAdapter
SpinnerAdapter
From source file:fr.shywim.antoinedaniel.ui.fragment.VideoListFragment.java
private void setupToolbarSpinner(Spinner spinner) { spinner.setAdapter(new SpinnerAdapter() { private static final String TAG_DROPDOWN = "dropdown"; private static final String TAG_NOT_DROPDOWN = "not_dropdown"; String[] titles = getResources().getStringArray(R.array.dropdown_videos_list_titles); @Override/*from ww w.j av a 2s .c o m*/ public View getDropDownView(int position, View convertView, ViewGroup parent) { if (convertView == null || !convertView.getTag().toString().equals(TAG_NOT_DROPDOWN)) { convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.spinner_actionbar_item, parent, false); convertView.setTag(TAG_NOT_DROPDOWN); } if (position != 0) { convertView.findViewById(R.id.divider_view).setVisibility(View.GONE); } else { convertView.findViewById(R.id.divider_view).setVisibility(View.VISIBLE); } TextView tv = (TextView) convertView.findViewById(android.R.id.text1); tv.setText(getTitle(position)); return convertView; } @Override public void registerDataSetObserver(DataSetObserver observer) { } @Override public void unregisterDataSetObserver(DataSetObserver observer) { } @Override public int getCount() { return titles.length; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public boolean hasStableIds() { return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null || !convertView.getTag().toString().equals(TAG_DROPDOWN)) { convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.spinner_actionbar, parent, false); convertView.setTag(TAG_DROPDOWN); } TextView tv = (TextView) convertView.findViewById(android.R.id.text1); tv.setText(getTitle(position)); return convertView; } @Override public int getItemViewType(int position) { return 0; } @Override public int getViewTypeCount() { return 1; } @Override public boolean isEmpty() { return false; } private String getTitle(int position) { return titles[position]; } }); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { int[] colors = getResources().getIntArray(R.array.spinner_videos_color_array); int actualPosition = 0; @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Filter filter = ((CursorRecyclerAdapter) listView.getAdapter()).getFilter(); UiUtils.animateToolbarStatusBarColor(mToolbar, mStatusBarBg, colors[position], colors[actualPosition]); switch (position) { case 0: filter.filter(null); break; case 1: filter.filter("playlist_wtc"); break; case 2: filter.filter("playlist_lvn"); break; } actualPosition = position; } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }