Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.support.v4.widget.SimpleCursorAdapter;

import android.widget.Spinner;

public class Main {
    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;
            }
        }
        spinner.setSelection(0);
    }
}