Example usage for android.widget Spinner getAdapter

List of usage examples for android.widget Spinner getAdapter

Introduction

In this page you can find the example usage for android.widget Spinner getAdapter.

Prototype

@Override
    public SpinnerAdapter getAdapter() 

Source Link

Usage

From source file:Main.java

public static void setSpinnerSelectionById(Spinner spinner, int itemId) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) spinner.getAdapter();
    for (int position = 0; position < adapter.getCount(); position++) {
        if (adapter.getItemId(position) == itemId) {
            spinner.setSelection(position);
            return;
        }/*from  w  ww. jav  a2s  .  co  m*/
    }
    spinner.setSelection(0);
}

From source file:Main.java

public static void setSpinnerSelection(Spinner spinner, int position) {
    if (spinner.getSelectedItemPosition() != position) {
        spinner.setSelection(position);//from   ww  w  .  ja v a2 s  . co  m
    } else {
        spinner.getOnItemSelectedListener().onItemSelected(spinner, spinner.getSelectedView(), position,
                spinner.getAdapter().getItemId(position));
    }
}

From source file:mobile.tiis.appv2.helpers.Utils.java

public static void setSpinnerSelection(Spinner spinner, String value) {
    @SuppressWarnings("unchecked")
    ArrayAdapter<String> adapter = (ArrayAdapter<String>) spinner.getAdapter();
    int spinnerPosition = adapter.getPosition(value);
    spinner.setSelection(spinnerPosition);
}

From source file:com.udacity.interpolationdemo.MainActivity.java

@OnItemSelected({ R.id.interpolator_spinner })
void onItemSelected(Spinner spinner, int position) {
    String interpolatorName = (String) spinner.getAdapter().getItem(position);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    textView.setTranslationY(metrics.heightPixels);

    try {//w  ww. j  ava 2 s  .  c o  m
        String path = findFullInterpolatorPath(interpolatorName);
        if (path == null)
            return;

        interpolator = (Interpolator) Class.forName(path).newInstance();
        textView.animate().setInterpolator(interpolator).setDuration(duration).setStartDelay(500)
                .translationYBy(-metrics.heightPixels).start();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.udacity.interpolationdemo.MainActivity.java

@OnItemSelected({ R.id.duration_spinner })
void durationSelected(Spinner spinner, int position) {
    String durationString = (String) spinner.getAdapter().getItem(position);
    switch (durationString) {
    case "100ms":
        duration = 100;//from w  w  w .jav  a  2 s.co m
    case "900ms":
        duration = 900;
        break;
    case "1500ms":
        duration = 1500;
        break;
    case "3000ms":
        duration = 3000;
        break;
    default:
        duration = 300;
        break;
    }
    // Kick off transition
    int item = interpolatorSpinner.getSelectedItemPosition();
    onItemSelected(interpolatorSpinner, position);
}

From source file:com.example.android.wizardpager.wizard.ui.ProfessorCityFromFragment.java

private void resetSpinner(Spinner spinner) {
    if (spinner.getAdapter() != null && spinner.getAdapter().getCount() > 0) {
        spinner.setAdapter(null);//from w w w  .jav  a 2  s . c  o m
    }
}

From source file:ng.uavp.ch.ngusbterminal.SettingsFragment.java

private void SetSpinnerSelection(SharedPreferences sharedPref, Spinner spinner, String key, int defValue) {

    String str = String.valueOf(sharedPref.getInt(key, defValue));

    for (int i = 0; i < spinner.getAdapter().getCount(); i++) {
        String s = spinner.getItemAtPosition(i).toString();
        if (s.equals(str)) {
            spinner.setSelection(i);/* w  ww. j a va  2s .co  m*/
            break;
        }
    }
}

From source file:org.jboss.aerogear.android.cookbook.aerodoc.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    application = (AeroDocApplication) getApplication();

    contentPanel = findViewById(R.id.contentPanel);

    availableLeadsFragments = new AvailableLeadsFragments();
    acceptedLeadsFragments = new AcceptedLeadsFragments();

    // -- Dropdown (Status)

    Spinner spinner = (Spinner) findViewById(R.id.status);

    ArrayAdapter<String> spinnerAdapter = (ArrayAdapter) spinner.getAdapter();
    int actualStatus = spinnerAdapter.getPosition(application.getSaleAgent().getStatus());
    spinner.setSelection(actualStatus, true);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from  www.j  a v a  2  s  .  c o  m
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
            String status = (String) adapterView.getItemAtPosition(position);
            if (!application.getSaleAgent().getStatus().equals(status)) {
                updateStatus(status);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });

    // -- Tabs (Leads - Available & Archived)

    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);

    pager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
    tabs.setupWithViewPager(pager);
}

From source file:com.tassadar.multirommgr.installfragment.InstallCard.java

private void restoreInstanceState() {
    CheckBox b = (CheckBox) m_view.findViewById(R.id.install_multirom);
    b.setChecked(m_savedState.getBoolean("install_multirom", b.isChecked()));

    b = (CheckBox) m_view.findViewById(R.id.install_recovery);
    b.setChecked(m_savedState.getBoolean("install_recovery", b.isChecked()));

    b = (CheckBox) m_view.findViewById(R.id.install_kernel);
    String kernel = m_savedState.getString("install_kernel");
    if (kernel != null) {
        if (kernel.equals("false")) {
            b.setChecked(false);/*from   ww  w .ja v a2  s  .c  o m*/
        } else {
            b.setChecked(true);
            Spinner s = (Spinner) m_view.findViewById(R.id.kernel_options);
            for (int i = 0; i < s.getAdapter().getCount(); ++i) {
                if (((String) s.getItemAtPosition(i)).equals(kernel)) {
                    s.setSelection(i);
                    break;
                }
            }
        }
    }

    m_savedState = null;
}

From source file:com.tassadar.multirommgr.installfragment.InstallCard.java

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.install_btn: {
        Bundle extras = new Bundle();

        Bundle bundle = new Bundle();
        bundle.putString("installation_type", "multirom");

        CheckBox b = (CheckBox) m_view.findViewById(R.id.install_multirom);
        bundle.putBoolean("install_multirom", b.isChecked());

        b = (CheckBox) m_view.findViewById(R.id.install_recovery);
        bundle.putBoolean("install_recovery", b.isChecked());

        b = (CheckBox) m_view.findViewById(R.id.install_kernel);
        bundle.putBoolean("install_kernel", b.isChecked());

        if (b.isChecked()) {
            Spinner s = (Spinner) m_view.findViewById(R.id.kernel_options);
            String name = (String) s.getAdapter().getItem(s.getSelectedItemPosition());
            bundle.putString("kernel_name", name);
        }/*from www .  java 2  s.  co m*/

        extras.putBundle("installation_info", bundle);

        m_listener.startActivity(extras, MainActivity.ACT_INSTALL_MULTIROM, InstallActivity.class);
        break;
    }
    case R.id.changelog_btn: {
        Changelog[] logs = m_manifest.getChangelogs();
        String[] names = new String[logs.length];
        String[] urls = new String[logs.length];

        for (int i = 0; i < logs.length; ++i) {
            names[i] = logs[i].name;
            urls[i] = logs[i].url;
        }

        Bundle b = new Bundle();
        b.putStringArray("changelog_names", names);
        b.putStringArray("changelog_urls", urls);

        m_listener.startActivity(b, MainActivity.ACT_CHANGELOG, ChangelogActivity.class);
        break;
    }
    }
}