Linked Questions

Popular Questions

Basic Query about Spinner INVALID_POSITION

Asked by At

As per Android Docs,

public int getSelectedItemPosition ()

Since: API Level 1 Return the position of the currently selected item within the adapter's data set Returns int Position (starting at 0), or INVALID_POSITION if there is nothing selected.

Now i want to know in which case/situation INVALID_POSITION is returned , since when spinner is initialized it default position is set to 0 .

  Spinner spinner=(Spinner)findViewById(;
    ArrayAdapter<String> adapterVehicleList = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, vehicleTypeList);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub


        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub


    int position =spinner.getSelectedItemPosition();
             position =spinner.getSelectedItemPosition();
    Toast.makeText(this,String.valueOf(position),Toast.LENGTH_LONG).show();code here

Related Questions