Code example for SimpleCursorAdapter

Methods: setDropDownViewResource

        final int[] to = new int[] { };
        final Cursor cursor = adapter.fetchAll();
        // not sure about managing cursors for later versions of Android 
        final SimpleCursorAdapter ad = new SimpleCursorAdapter(activity, R.layout.simple_spinner_item, cursor, from, to);
        final Spinner spinner = (Spinner)activity.findViewById(id);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(final AdapterView<?> adapterView, final View view, final int i, final long l) {
                final Cursor c = (Cursor) spinner.getSelectedItem();
                if (c != null) {
                    final int index = c.getColumnIndex(value);
                    if (index >= 0);
            public void onNothingSelected(final AdapterView<?> adapterView) {
Contextual code suggestions in your IDE  Get Codota for Java