Search in sources :

Example 1 with SpinnerAdapter

use of android.widget.SpinnerAdapter in project materialistic by hidroh.

the class SpinnerPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    final Spinner spinner = (Spinner) holder.findViewById(R.id.spinner);
    holder.itemView.setOnClickListener(v -> spinner.performClick());
    spinner.setAdapter(new SpinnerAdapter() {

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = createDropDownView(position, parent);
            }
            bindDropDownView(position, convertView);
            return convertView;
        }

        @Override
        public void registerDataSetObserver(DataSetObserver observer) {
        // no op
        }

        @Override
        public void unregisterDataSetObserver(DataSetObserver observer) {
        // no op
        }

        @Override
        public int getCount() {
            return mEntries.length;
        }

        @Override
        public Object getItem(int position) {
            // not applicable
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public boolean hasStableIds() {
            return true;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return getDropDownView(position, convertView, parent);
        }

        @Override
        public int getItemViewType(int position) {
            return 0;
        }

        @Override
        public int getViewTypeCount() {
            return 1;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    });
    spinner.setSelection(mSelection);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mSelection = position;
            persistString(mEntryValues[position]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // no op
        }
    });
}
Also used : SpinnerAdapter(android.widget.SpinnerAdapter) Spinner(android.widget.Spinner) ViewGroup(android.view.ViewGroup) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) DataSetObserver(android.database.DataSetObserver)

Example 2 with SpinnerAdapter

use of android.widget.SpinnerAdapter in project Jota-Text-Editor-old by jiro-aqua.

the class FileSelectorActivity method selectItemOfSpinner.

private void selectItemOfSpinner(Spinner spinner, String s) {
    SpinnerAdapter adapter = spinner.getAdapter();
    int max = adapter.getCount();
    for (int i = 0; i < max; i++) {
        String item = (String) adapter.getItem(i);
        if (s.equals(item)) {
            spinner.setSelection(i);
            break;
        }
    }
    return;
}
Also used : SpinnerAdapter(android.widget.SpinnerAdapter)

Example 3 with SpinnerAdapter

use of android.widget.SpinnerAdapter in project xabber-android by redsolution.

the class NoDefaultSpinner method setAdapter.

@Override
public void setAdapter(SpinnerAdapter orig) {
    final SpinnerAdapter adapter = newProxy(orig);
    super.setAdapter(adapter);
    try {
        final Method m = AdapterView.class.getDeclaredMethod("setNextSelectedPositionInt", int.class);
        m.setAccessible(true);
        m.invoke(this, -1);
        final Method n = AdapterView.class.getDeclaredMethod("setSelectedPositionInt", int.class);
        n.setAccessible(true);
        n.invoke(this, -1);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SpinnerAdapter(android.widget.SpinnerAdapter) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with SpinnerAdapter

use of android.widget.SpinnerAdapter in project howabout-android by recomio.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    categoryStrings = getResources().getStringArray(R.array.category_list);
    musicPlaylistTitle = getResources().getString(R.string.title_activity_music_playlist);
    exit = getResources().getString(R.string.exit);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setDisplayShowTitleEnabled(false);
    // dropdown menu in actionBar.
    final SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.category_list, android.R.layout.simple_list_item_1);
    actionBar.setListNavigationCallbacks(spinnerAdapter, new HowaboutDropdownNavigationListener());
    // set framgents.
    adultCategoryWrapFragment = new AdultCategoryWrapFragment();
    Bundle adultCategoryWrapFragmentBundle = new Bundle();
    adultCategoryWrapFragmentBundle.putString("category", "adult");
    adultCategoryWrapFragment.setArguments(adultCategoryWrapFragmentBundle);
    musicCategoryWrapFragment = new MusicCategoryWrapFragment();
    Bundle musicCategoryWrapFragmentBundle = new Bundle();
    musicCategoryWrapFragmentBundle.putString("category", "music");
    musicCategoryWrapFragment.setArguments(musicCategoryWrapFragmentBundle);
    setAdsContainer(R.id.adView);
}
Also used : SpinnerAdapter(android.widget.SpinnerAdapter) MusicCategoryWrapFragment(io.recom.howabout.category.music.fragment.MusicCategoryWrapFragment) Bundle(android.os.Bundle) AdultCategoryWrapFragment(io.recom.howabout.category.adult.fragment.AdultCategoryWrapFragment) ActionBar(com.actionbarsherlock.app.ActionBar)

Example 5 with SpinnerAdapter

use of android.widget.SpinnerAdapter in project robolectric by robolectric.

the class ShadowAbsSpinner method setSelection.

@Implementation
public void setSelection(int position) {
    directlyOn(realAbsSpinner, AbsSpinner.class, "setSelection", ClassParameter.from(int.class, position));
    SpinnerAdapter adapter = realAbsSpinner.getAdapter();
    if (getItemSelectedListener() != null && adapter != null) {
        getItemSelectedListener().onItemSelected(realAbsSpinner, null, position, adapter.getItemId(position));
    }
}
Also used : SpinnerAdapter(android.widget.SpinnerAdapter) Implementation(org.robolectric.annotation.Implementation)

Aggregations

SpinnerAdapter (android.widget.SpinnerAdapter)9 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 DataSetObserver (android.database.DataSetObserver)1 Bundle (android.os.Bundle)1 ViewGroup (android.view.ViewGroup)1 Spinner (android.widget.Spinner)1 ActionBar (com.actionbarsherlock.app.ActionBar)1 MyListAdapter (com.haarman.listviewanimations.MyListAdapter)1 AdultCategoryWrapFragment (io.recom.howabout.category.adult.fragment.AdultCategoryWrapFragment)1 MusicCategoryWrapFragment (io.recom.howabout.category.music.fragment.MusicCategoryWrapFragment)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Implementation (org.robolectric.annotation.Implementation)1